问题
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?
回答1:
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>
回答2:
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
.
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/41036273/disable-autostart-of-docker-compose-project