Whenever I start Docker on my Mac, there are four containers that come along for the ride and start up automatically.
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
//starts docker, makes tea
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d78483fa7f27 magento/magento2devbox-web:latest "/usr/local/bin/en..." 4 weeks ago Up 5 minutes 5000/tcp, 9000/tcp, 44100/tcp, 0.0.0.0:32774->22/tcp, 0.0.0.0:32773->80/tcp magento2devbox_web_03b003abaeb68eadd315c2e4763d0326
01f62a720e40 mysql:5.6 "docker-entrypoint..." 4 weeks ago Up 5 minutes 0.0.0.0:32772->3306/tcp magento2devbox_db_03b003abaeb68eadd315c2e4763d0326
005e0708d8f7 magento/magento2devbox-web:latest "/usr/local/bin/en..." 6 months ago Up 5 minutes 5000/tcp, 9000/tcp, 44100/tcp, 0.0.0.0:32770->22/tcp, 0.0.0.0:32769->80/tcp magento2devbox_web_258e08743d8e54a4b3e6acfd3b2d7159
00b38cf0fdb9 mysql:5.6 "docker-entrypoint..." 6 months ago Up 5 minutes 0.0.0.0:32768->3306/tcp magento2devbox_db_258e08743d8e54a4b3e6acfd3b2d715
How do I tell (Docker? The containers?) that I don’t need these four containers to start up automatically anymore?
2
Answers
Use
docker stop [container_id]
to stop each running container. They should not start back up the next time you restart the docker daemon.In the future, when you start the containers, make sure that when you call
docker run
you’re not passing the--restart
flag. If you’re using docker compose make sure to omit the ‘restart’ option from your docker-compose.yml file.From the documentation:
https://docs.docker.com/engine/admin/start-containers-automatically/#use-a-restart-policy
Check the restart policy of those containers using
docker inspect NAME|ID
.If it is
always
oron-failure
, then you have the explanation.To change the restart policy, use
docker update --restart <new policy>
.These two commands set the restart policy to
no
for all running containers and then kill them all (make sure you understand this before doing it):After that, restart your docker daemon and you should see nothing from
docker ps
.