This question already has answers here:
Unable to find user root: no matching entries in passwd file in Docker
(3 answers)
Closed 4 years ago.
Yesterday I restarted my docker container for my database. My applications can still connect as normal however:
The following line no-longer works
docker exec -i -t database_1 bash
Instead it gives me this error:
unable to find user postgres: no matching entries in passwd file
I don't know why it's not just giving me bash
It looks as if you switched to a different user in the Dockerfile, but never created it. Try this:
docker exec -it --user root database_1 /bin/bash
This is some sort of bug in docker. Apparently docker stop <container>; docker start <container> will fix it, and using docker cp can cause it to happen.
Related
This question already has answers here:
running docker container without /bin/bash command
(2 answers)
Closed 1 year ago.
I am self-studying docker basics and I am not sure what's the difference when we use "docker run -it centos" vs "docker run -it centos /bin/bash". I tested two commands and both of them seem to start a centos terminal.
See next:
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
The /bin/bash after image is called COMMAND, but for centos, the default command already defined in Dockerfile, see this:
FROM scratch
ADD centos-8-x86_64.tar.xz /
LABEL org.label-schema.schema-version="1.0" org.label-schema.name="CentOS Base Image" org.label-schema.vendor="CentOS" org.label-schema.license="GPLv2" org.label-schema.build-date="20201204"
CMD ["/bin/bash"]
So, the situation you mentioned above same here.
I'm running the intro tutorial for Docker on Mac and am getting an error as follows:
docker run -d -p 80:80 --name docker-tutorial docker101tutorial
docker: Error response from daemon: Conflict. The container name "/docker-tutorial" is already in use by container "c5a91ef51a529a00dcbef180560dc2b392f3d9ab05b8c29fa1bf640d64271de7". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'.
Can you advise on this error — it seems that I would need to delete a prior container? But I don't believe I created one.
Can anyone please advise as to how to troubleshoot this issue as I am not very proficient in terminal and am new to Docker.
When I type docker ps -a, I get:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5ed32612a0a ubuntu "bash" 27 minutes ago Exited (129) 22 minutes ago happy_tesla
b179c651b8d7 hello-world "/hello" 40 minutes ago Exited (0) 40 minutes ago mystifying_rubin
c5a91ef51a52 docker101tutorial "/docker-entrypoint.…" 42 minutes ago Created docker-tutorial
916e57976203 hello-world "/hello" 48 minutes ago Exited (0) 48 minutes ago exciting_dewdney
To make it short, the reason why this is happening to you is because, when you name containers (with the flag --name foo), then you have to make sure this name is unique among all the containers you have on your host.
Then regarding your statement:
Can you advise on this error - it seems that I would need to delete a prior container? But I don't believe I created one
If I read your docker ps -a output, this is untrue, you created one 42 minutes ago, see the really last bit of the below line? This is the name of an existing container, docker-tutorial:
c5a91ef51a52 docker101tutorial "/docker-entrypoint.…" 42 minutes ago Created docker-tutorial
Just run:
docker rm docker-tutorial
Then you should be able to go back your tutorial.
For the sake of completeness, since it can be unexpected at first usage, the command docker rm will output back the name of the container that it just deleted:
$ docker rm I-do-exist
I-do-exist
And if you do not have such a named container, then it will output a clear error:
$ docker rm I-do-not-exist
Error: No such container: I-do-not-exist
The command being docker run and not run, I suspect there might be some typo, maybe a non-printable character.
Try to type the complete command from a fresh prompt.
Please post the command you are running again removing the backslash
Please post output docker ps -a it will show you what containers are there running/stopped
You can solve your problem with just two commands
In your terminal type:
docker ps -qa
to find the name that you called your docker container and check the its status says 'exited'(i.e. Container called 'Zen-wu')
Select your docker container number and remove it like the example below
docker rm 828a52b426f2
optional
If you want to remove All the exited docker containers do the following command
docker rm $(docker ps -qa)
I'm very new to docker.
Also I'm using Docker for Windows (ie Image and Container are for Windows OS).
I'm trying to get a list of all the folders and subfolders to resolve another issue I'm having. I read several post and blogs and seems like I should be able to run
docker exec -it <container id> dir
To get the info as it is suppose to allow me to run commands against the container.
I even ran
docker exec -it f83eb1533b67 help
which gave me a list of commands (because no one tells what are acceptable 'commands'...) and it is listed. however I get the following message when I run DIR command
PS P:\docker\tmp\SqlServerSetup> `docker exec -it f83eb1533b67 dir`
container f83eb1533b671b4462b8a1562da7343185b2dd27e94ff360e0230969d432ec37 encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"dir","WorkingDirectory":"C:\\","Environment":{"ACCEPT_EULA":"Y","attach_dbs":"[]","sa_password":"Pass1.4DBAs","sa_password_path":"C:\\ProgramData\\Docker\\secrets\\sa-password"},"EmulateConsole":true,"CreateStdInPipe":true,"CreateStdOutPipe":true,"ConsoleSize":[0,0]}
PS P:\docker\tmp\SqlServerSetup>
Please note: I don't want to persist a volume. Seems like that option is for people that are trying to reuse data.
UPDATE:
This is the statement that i'm using to create the container:
docker run -p 1433:1433 -e sa_password=Pass1.4DBAs -e ACCEPT_EULA=Y -p 11433:1433 --name sqlTraining --cap-add SYS_PTRACE -d microsoft/mssql-server-windows-developer
It works fine. Container is created, but I want to view the filesystem within that container.
For Windows containers, prefix the command with the command shell (cmd) and the /c parameter. For example:
docker exec <container id> cmd /c dir
This will execute the dir command on the specified container and terminate.
Try running:
docker exec -it <container id> sh
to start the interactive shell console. This should help you with debugging.
I´m executing following command:
sudo docker run IMAGE bash ~/commands.sh
where IMAGE is my docker image and commands.sh a script inside the container.
When starting the container with "docker run", I want to execute the script. But it doesn´t work. I get the following error-status:
Exited (127) Less than a second ago
This error-status means, it doesn´t know the command.
Can you tell me where my mistake is?
I would assume that your local bash (running on the host system) expands the ~ before it reaches the running docker container. Have you tried using an absolute path here?
I have a container that is running with no issues. I added a bash script to compliment a couple other scripts already in the container. The docker image copy 2 scripts to /usr/local/bin and they can be accessed with docker exec -c container-name existingscript.
I added my own script to the same directory and when running the same command I get an error that exec cannot run the script: no file or directory,script not located in $PATH. I check path and sure enough, /usr/local/bin is listed. I checked permissions and the script is 755.
I then open an interactive shell with docker exec -it mycontainer bash and run /usr/local/bin/myscript and it runs with no problem.
Why can I not run the script from outside the container like I can the other two (that were included in the image). All three have almost the same functions a day do not use any special programs, one lists files, one adds files, one reads the file.
The base is Ubuntu.
EDIT: Found where I was running into the issue. Provided the answer in case anyone else happens to make the same mistake.
EDIT-2: So the script that came with the docker image to perform a couple common functions calls the image not the container so my adding the scripts to the container had no effect on the script which was why I kept getting the no file or directory error.
The line in the script in question was:
docker run --rm -v "$(pwd)/config":/path/to/file -ti image_name:latest" mynewscript $#
Of course that ran against the image and NOT the container.
Once I noticed that I tried running it with exec instead of run and it ran without error, like so:
docker exec -it container_name mynewscript
The reason is "/usr/local/bin" not in your script's $PATH, you can use /usr/local/bin/myscript explicitly in your script. Or export $PATH first in the script.
While I was adding snippets to help explain the issue I found the problem and the solution.
So I access the scripts inside the container from the host with another script that allows you to do different things based on switch case. The scripts are called against the docker image and not the container so the script I added does not actually exist in the image.
I modified the script to call the container instead of the image and it works as expected.
EDIT: I updated the question with the answer but I am adding it here as well:
So the script that came with the docker image to perform a couple common functions calls the image not the container so my adding the scripts to the container had no effect on the script which was why I kept getting the no file or directory error.
The line in the script in question was:
docker run --rm -v "$(pwd)/config":/path/to/file -ti image_name:latest" mynewscript $#
Of course that ran against the image and NOT the container.
Once I noticed that I tried running it with exec instead of run and it ran without error, like so:
docker exec -it container_name mynewscript