I'm using docker-compose to add a new ubuntu container but the container keeps restarting and I don't know why... any clue of what I can check ?
here my docker-compose service:
ubuntu:
image: ubuntu
container_name: ubuntu
network_mode: host
restart: unless-stopped
volumes:
- /mnt:/NAS:rw
environment:
- TZ="Asia/Shanghai"
and here is the docker ps output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c084528838c ubuntu "/bin/bash" 6 minutes ago Restarting (0) 18 seconds ago ubuntu
i'm using Docker 17.09 on Ubuntu server 17.04 and I'm running the container with this alias:
alias dcrun='docker-compose -f /home/docker-compose.yml'
dcrun up -d ubuntu
Thank you
This is quite expected since you haven't defined any command:
or entrypoint:
in the docker compose.
Ubuntu image by default has bash
command as CMD
which isn't really a foreground process.
Ref - https://github.com/dockerfile/ubuntu/blob/master/Dockerfile
If you run it in interactive mode(-i), you will dive into bash
automatically -
$ docker run -it ubuntu
root@8d6ac0591d88:/#
Hence, once the bash
command exits your container also dies but due to your restart: unless-stopped
policy, Docker daemon keeps trying to restart it.
If you want your container to be up & running with compose, try defining a foreground process as below -
ubuntu:
image: ubuntu
container_name: ubuntu
network_mode: host
restart: unless-stopped
volumes:
- /mnt:/NAS:rw
environment:
- TZ="Asia/Shanghai"
command: "tail -f /dev/null"
Your container will not restart now -
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cee860adf641 ubuntu "tail -f /dev/null" 5 seconds ago Up 3 seconds ubuntu
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