Disable autostart of docker-compose project

Docker ComposeAutostartDocker for-Mac

Docker Compose Problem Overview


I have a docker-compose project using Docker for Mac that autostarts when I boot the computer.

I usually start the project with docker-compose up -d, but even running docker-compose stop before shutting down autostarts it again on boot.

I am not aware of specifically enabling this. How can I disable it?

Docker Compose Solutions


Solution 1 - Docker Compose

Today I had the same issue that all containers are started when I boot my dev laptop, as restart: always was set in the .yml files.

As I don't want to touch the .yml files, I just found out (thx Bobby) how to alter this setting by:

docker update --restart=no <MY-CONTAINER-ID>

Solution 2 - Docker Compose

Try with docker-compose down instead of docker-compose stop

down

Stops containers and removes containers, networks, volumes, and images created by up. Networks and volumes defined as external are never removed.

stop

Stops running containers without removing them. They can be started again with docker-compose start.

Solution 3 - Docker Compose

restart: no is default mode. There is line inside your docker-compose file with restart: no or restart: unless-stopped. It also means that when you boot your system, it (re)starts container(s) again as long as docker daemon. Details
You need to change restart to no or on-failure, example:

version: '2.1'
services:
    backend:
        restart: on-failure
        build:
            args:
                USER_ID: ${USER_ID}
            context: codebase/namp-backend
            dockerfile: Dockerfile.dev
        ports:
          - "5001:5001"
          - "5851:5851"
        volumes:
          - ./codebase/namp-backend:/codebase
        environment:

Also docker-compose down for most cases, gives you the same result - do not start containers while (docker) system startup, except: containers will be deleted after this, not stopped.

Solution 4 - Docker Compose

Use the following command if you want to stop a specific container:

docker update --restart=no <MY-CONTAINER-ID>

If you want to stop all registered containers, this is the best option:

docker update --restart=no $(docker container ls -a -q)

Thank you

Solution 5 - Docker Compose

Beside setting restart: unless-stopped, remove existing containers and recreate them.

docker-compose down
docker-compose up -d

Now, it would work as expected:

docker-compose stop
sudo service docker restart
docker-compose ps
# should NOT HAVE containers running

docker-compose up -d
sudo service docker restart
docker-compose ps
# should HAVE containers running

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarald NordgrenView Question on Stackoverflow
Solution 1 - Docker ComposedaveyView Answer on Stackoverflow
Solution 2 - Docker Composevanduc1102View Answer on Stackoverflow
Solution 3 - Docker ComposeGrigoryView Answer on Stackoverflow
Solution 4 - Docker ComposeHudson Van-dalView Answer on Stackoverflow
Solution 5 - Docker ComposebmihelacView Answer on Stackoverflow