I have 2 services with 2 different images in my docker-compose.yml, when I run "docker-compose up -d", containers are started properly, but when i try to do "docker attach ", container restarts.
Can anyone please explain this behavior. How can attach to the container?
You can use the --restart=unless-stopped option, as @Shibashis mentioned, or update the restart policy (this requires docker 1.11 or newer); See the documentation for docker update and Docker restart policies. Use docker update --restart=no $(docker ps -a -q) to update all your containers :-) Great answer!!
However, Docker Compose allows us to configure restart policies to manage multiple containers by using the restart or restart_policy properties in normal mode or swarm mode.
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. always Always restart the container if it stops.
It is possible to grant a container access to docker so that it can spawn other containers on your host. You do this by exposing the docker socket inside the container, e.g: docker run -v /var/run/docker. sock:/var/run/docker.
if you want to go to your running compose container you can start new shell
and attach to it
docker-compose exec servicename sh
or if you really want to attach to it just do docker-compose up
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With