Trying to stop container from this image by using either of mentioned commands results in indefinite waiting by docker. The container still can be observed in docker ps output.
Sorry for a newbie question, but how does one stop containers properly?
This container was first run according to the instructions on hub.docker.com, halted by Ctrl+C and then started again by docker start <containter-name>. After it was started, it never worked as expected though.
Your test worked for me:
→ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
853e36b8a952 jleight/opentsdb "/usr/bin/supervisord" 9 minutes ago Up 9 minutes 0.0.0.0:4242->4242/tcp fervent_hypatia
→ docker stop fervent_hypatia
fervent_hypatia
→ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
It took a bit long, but I think that is because the Docker image is using a supervisor process so SIGTERM (which is what docker stop sends first) doesn't kill the container, but the SIGKILL, which is by default sent after 10 seconds should (my wait time was ~ 10 seconds).
Just in case your default may be messed up for some reason, try indicating the timeout explicitely:
docker stop --time=2 <container-name>
docker stop <container-name> is a proper way to stop your container. It's possible there is something going on inside, you could try usingdocker logs <container-name> to give you more information about what's running inside.
This probably isn't the best way, but eventually restarting docker would do the trick, if nothing else works.
Related
I have been running a nvidia docker image since 13 days and it used to restart without any problems using docker start -i <containerid> command. But, today while I was downloading pytorch inside the container, download got stuck at 5% and gave no response for a while.
I couldn't exit the container either by ctrl+d or ctrl+c. So, I exited the terminal and in new terminal I ran this docker start -i <containerid> again. But ever since this particular container is not responding to any command. Be it start/restart/exec/commit ...nothing! any command with this container ID or name is just non-responsive and had to exit out of it only after ctrl+c
I cannot restart the docker service since it will kill all running docker containers.
Cannot even stop the container using this docker container stop <containerid>
Please help.
You can make use of docker RestartPolicy:
docker update --restart=always <container>
while mindful of caveats on the docker version you running.
or explore an answer by #Yale Huang from a similar question: How to add a restart policy to a container that was already created
I had to restart docker process to revive my container. There was nothing else I could do to solve it. used sudo service docker restart and then revived my container using docker run. I will try to build the dockerfile out of it in order to avoid future mishaps.
I would like to stop my running docker container after a specific time, let's say 2 hrs after startup. So far my research has led to the following solutions. I just wanted to know if there were better ways to do it.
Use a cron job to stop the container by calling the docker stop command.
Use an entry point like sleep 5000, but this does not suit my use case.
Using --stop-timeout in the docker run command ; I believe this is just the maximum timeout given for the container to gracefully shutdown. Am I missing something
here?
You can use the timeout command that's part of the coreutils package which is already installed in the debian images (and probably many others).
This will run the container for 30 seconds and then stop
docker run debian timeout 30 tail -f /dev/null
Basically, add timeout 7200 in front of the command you want to run in the container, and it'll be killed after 2 hours.
I am just studying the Docker and found out it seems that we don't need to run docker-tutorial image and the port:80 is always listened on just like below picture:
At first, I thought it is automatically managed by Docker Desktop. But it is not. Because after I close the Docker desktop completely, it is still there.
I even run a command to check the process of port 80 and no process is there:
when no process is on this port, it is still running. It drives me crazy. I do have followed docker start tutorial to run this tutorial web application and at that time I can also open localhost:80.
After that, I have stopped and removed container and even the image as well as closing the Docker app, the page, however, is still there.
Does any have encountered this situation or have any idea? How does Docker do this?
After a day, i start my mac again without running Docker and it is still there in a messy way:
By the looks of the page, it is running off the browser cache. Clear the cache or open an incognito window to use the newly created services on port 80.
Try stopping the container. E.g.
List running containers.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b223e7cc8c5 docker/getting-started "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp wonderful_goldstine
Stopping the docker/getting-started container with its container ID.
$ docker stop 4b223e7cc8c5
4b223e7cc8c5
At this point, the container will have stopped and port 80 will be free. It will still be on your machine if you ever want to restart it, but you can remove it with:
$ docker rm 4b223e7cc8c5
4b223e7cc8c5
I had the same issue but in my case it' was just a cache in the browser. After stopping the docker image or deleted it, it will work probably
For stop it.
$ docker stop [CONTAINER ID]
for delete it
$ docker rm [CONTAINER ID]
here my snippet:
docker restart -t 5 waitforit_
then docker ps returns immediately :
status => run since 1s
How it is possible?
any hint would be great,
thanks
I believe docker restart is equivalent to docker stop; docker start. The -t option isn’t a hard wait. Rather, it says that if the process doesn’t stop on its own after receiving SIGTERM, then send it SIGQUIT (kill -9) after that many seconds.
If your process is well-behaved and exits promptly when it receives SIGTERM, then docker restart will in fact be pretty quick, regardless of whatever value you pass as -t.
I'd love a consistent way to drop a docker container into an error state to do some testing around container errors.
I was hopeful when I saw bantl23/error on the docker hub, but it happily starts with no error.
I like the idea of a container that you can cause to fail on demand from outside - R0MANARMY's point is valid though - Docker monitors the process it starts, and if the process exits then the container goes to the Exited status, there isn't really a concept of an error state.
Having said that, if you want to test an Exited container then the image you mentioned does work, but it's limited - it runs, waits for 10 seconds and then exits:
docker run -d bantl23/error
If you want something you can control from the outside, I've put a very simple image together for that - sixeyed/bad-server. It's an HTTP server that you can force into an error state by hitting http://ip:8080/err:
> docker run -d -p 80:8080 sixeyed/bad-server
8b4bd7ffd96d543c9b51c7709267894d2bc75daa99ea80250d5e7846f98a6526
> docker logs -f 8b4
+ exec app
Listening on port 8080
Responding to path:
test
err!
> docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b4bd7ffd96d sixeyed/bad-server "go-wrapper run" 37 seconds ago Exited (1) 10 seconds ago fervent_hawking
While the logs were running, I hit http://localhost/test and then http://localhost/err - which caused the container to exit.