I have the following docker-compose
file:
version: '2'
services:
ubuntu:
image: 'ubuntu:16.04'
ports:
- '22:22'
When start this, the container seems to crash, the following are the logs that I see:
Attaching to playground_ubuntu_1
ubuntu_1 | Error grabbing logs: EOF
playground_ubuntu_1 exited with code 0
My host OS is Ubuntu 16.04 with Docker version 17.12.0-ce, build c97c6d6
.
All of my other containers seem to start normally, but this one just flat out fails on boot.
This is normal. When you start a container it will run as long as the main process started inside the container is still running.
This process is specified using the CMD
command inside a Dockerfile. The ubuntu image does not have a CMD
as it is intended to be used as a building block for other docker images.
Thus when you run this image without specifying a command, it exits successful as can be seen from the 0 exit code.
If you want this image to stay alive just for testing, you can specify a command that will keep it living.
version: '2'
services:
ubuntu:
image: 'ubuntu:16.04'
ports:
- '22:22'
command: "tail -f /dev/null"
Exit status in log playground_ubuntu_1 exited with code 0
shows that its expected. In order to make a container up & running for long, you need to give/define a foreground process for your container. I have momentarily edited your compose file -
version: '2'
services:
ubuntu:
image: 'ubuntu:16.04'
ports:
- '22:22'
command: "tail -f /dev/null"
Now you run it -
$ docker-compose up -d && docker ps
Your container is up & running now.
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