Disable autostart of docker-compose project

后端 未结 4 2106
青春惊慌失措
青春惊慌失措 2021-02-06 21:11

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 ev

相关标签:
4条回答
  • 2021-02-06 21:41

    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
    
    0 讨论(0)
  • 2021-02-06 21:44

    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.

    0 讨论(0)
  • 2021-02-06 21:56

    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.

    0 讨论(0)
  • 2021-02-06 22:01

    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>
    
    0 讨论(0)
提交回复
热议问题