docker start
doesn't make a stopping container be "up".
As the following commands, I wanted to start up a stopping container eloquent_hamilton
(Container ID:b2b7883c8620) whose status is Exited (0)
, so I used docker start eloquent_hamilton
or docker start b2b7883c8620
.
However, the status of eloquent_hamilton
is still Exited (0)
.
The common case seems that just typing docker start [Container ID]
makes the status of the container be "UP" until the user explicitly send command for killing or exiting the running container.
What is wrong?
The environment is the following
- host OS: windows10
- Docker: Docker Desktop for Windows
Any information would be appreciated.
C:\Users\Naoki>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
forcattranslator/hello latest 64c8ea9561cc About an hour ago 72.8MB
forcattranslator/myjulia latest 84ec6294d0dc 2 days ago 4.24GB
hassiweb/myjulia julia-1.6.2 84ec6294d0dc 2 days ago 4.24GB
C:\Users\Naoki>docker run -it forcattranslator/hello
"hello docker!"
C:\Users\Naoki>docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2b7883c8620 forcattranslator/hello "cat /tmp/hello.txt" 21 seconds ago Exited (0) 19 seconds ago eloquent_hamilton
f7c65f29f81b forcattranslator/hello "cat /tmp/hello.txt" 48 seconds ago Exited (0) 46 seconds ago admiring_tereshkova
c47ac4b56d64 forcattranslator/hello "bash" 7 minutes ago Up 5 minutes thirsty_carson
9c83d47cfea2 forcattranslator/hello "cat /tmp/hello.txt" 9 minutes ago Exited (0) 7 minutes ago gifted_feynman
9d17957f8e43 forcattranslator/hello "cat /tmp/hello.txt" 18 minutes ago Exited (0) 17 minutes ago laughing_albattani
43b967492f0c forcattranslator/hello "cat /tmp/hello.txt" 46 minutes ago Exited (0) 22 minutes ago sad_wu
f97a713d6889 hassiweb/myjulia:julia-1.6.2 "tini -g -- start-no…" 2 days ago Up 2 days 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp docker-julia_julia_1
C:\Users\Naoki>docker start eloquent_hamilton
eloquent_hamilton
C:\Users\Naoki>docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2b7883c8620 forcattranslator/hello "cat /tmp/hello.txt" About a minute ago Exited (0) 4 seconds ago eloquent_hamilton
f7c65f29f81b forcattranslator/hello "cat /tmp/hello.txt" About a minute ago Exited (0) About a minute ago admiring_tereshkova
c47ac4b56d64 forcattranslator/hello "bash" 8 minutes ago Up 6 minutes thirsty_carson
9c83d47cfea2 forcattranslator/hello "cat /tmp/hello.txt" 10 minutes ago Exited (0) 8 minutes ago gifted_feynman
9d17957f8e43 forcattranslator/hello "cat /tmp/hello.txt" 19 minutes ago Exited (0) 17 minutes ago laughing_albattani
43b967492f0c forcattranslator/hello "cat /tmp/hello.txt" 47 minutes ago Exited (0) 22 minutes ago sad_wu
f97a713d6889 hassiweb/myjulia:julia-1.6.2 "tini -g -- start-no…" 2 days ago Up 2 days 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp docker-julia_julia_1
Progress
Following the answer, I tried docker start -i eloquent_hamilton
,adding -i
option to keep the communication interactive, but the result is still finding the status of the container be Exited(0)
.
docker start -i eloquent_hamilton
"hello docker!"
C:\Users\Naoki\tmp>docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2b7883c8620 forcattranslator/hello "cat /tmp/hello.txt" 22 hours ago Exited (0) 16 seconds ago eloquent_hamilton
f7c65f29f81b forcattranslator/hello "cat /tmp/hello.txt" 22 hours ago Exited (0) 22 hours ago admiring_tereshkova
c47ac4b56d64 forcattranslator/hello "bash" 22 hours ago Exited (255) 20 hours ago thirsty_carson
9c83d47cfea2 forcattranslator/hello "cat /tmp/hello.txt" 23 hours ago Exited (0) 22 hours ago gifted_feynman
9d17957f8e43 forcattranslator/hello "cat /tmp/hello.txt" 23 hours ago Exited (0) 23 hours ago laughing_albattani
43b967492f0c forcattranslator/hello "cat /tmp/hello.txt" 23 hours ago Exited (0) 23 hours ago sad_wu
f97a713d6889 hassiweb/myjulia:julia-1.6.2 "tini -g -- start-no…" 3 days ago Up 20 hours 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp docker-julia_julia_1
CodePudding user response:
It looks like your container is the hello world example container (or based on it). This container contains a single script which outputs something and then immediately afterwards is done. So "starting" it again worked (as on your screenshot you can see it exited 4 seconds ago) but it didn't do much.
Every docker container has a process that defines the container running time. At the point where this process ends, the container stops. In your case, it outputs the hello to somewhere and then quits (hence the "Exited (0) 4 seconds ago").
If you want it to keep running after this you need to make sure that the last process of the container is indefinite. This can be done in several ways, but most commonly you will find software that run for example a webserver.
[EDIT] In your example you first run with the "-it" flag, meaning the output will be redirected to your terminal (as can be seen in the out "Hello Docker"). The second and third time the container just runs and does not output to the terminal.
CodePudding user response:
your container simply cats the file /tmp/hello.txt. As @JustLudo pointed out, when you ran docker run -it forcattranslator/hello
, the container showed the content of file /tmp/hello.txt to the tty. Then it finished and thus the container was stopped.
When you start the container again, it executes the entry point again (cat /tmp/hello.txt) and finalizes again. That is what the container does, because in the first "run" you did not added any other command.
You can check the output by executing docker logs eloquent_hamilton
or start the container by making it interactive again by executing docker start -i eloquent_hamilton