skip to Main Content

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


  1. 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:

    To configure the restart policy for a container, use the –restart flag when using the docker run command. The value of the –restart flag can be any of the following:

    no – Do not automatically restart the container. (the default)

    on-failure – Restart the container if it exits due to an error, which manifests as a non-zero exit code.

    unless-stopped – Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted.

    always – Always restart the container if it stops.

    The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted.

    $ docker run -dit --restart unless-stopped redis

    https://docs.docker.com/engine/admin/start-containers-automatically/#use-a-restart-policy

    Login or Signup to reply.
  2. Check the restart policy of those containers using docker inspect NAME|ID.
    If it is always or on-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):

    docker update `docker ps -q` --restart no
    docker kill `docker ps -q`
    

    After that, restart your docker daemon and you should see nothing from docker ps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search