I have what is prob a Docker Compose 101 question. I can spin up a simple Docker container with docker run
:
me@host1:~/dc$
me@host1:~/dc$ sudo docker run -dit --name myContainer 54c9d81cbb44
60d254728f0a763bdda3078bd1c708176ca21e3eced475cb7e2c3edc7859a12c
me@host1:~/dc$
me@host1:~/dc$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60d254728f0a 54c9d81cbb44 "bash" 2 minutes ago Up 2 minutes myContainer
me@host1:~/dc$
Easy! So then, I translate the above into a docker-compose.yaml
file:
version: "2"
services:
myService:
container_name: myContainer2
image: 54c9d81cbb44
When I run the above file, the container exits immediately:
me@host1:~/dockerCompose$
me@host1:~/dockerCompose$ sudo docker-compose up
Creating myContainer2 ...
Creating myContainer2 ... done
Attaching to myContainer2
myContainer2 exited with code 0
me@host1:~/dockerCompose$
me@host1:~/dockerCompose$
me@host1:~/dockerCompose$ sudo docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
110f648fadbe 54c9d81cbb44 "bash" 14 seconds ago Exited (0) 13 seconds ago myContainer2
60d254728f0a 54c9d81cbb44 "bash" 6 minutes ago Up 6 minutes myContainer
me@host1:~/dockerCompose$
(The above happens even when I try to spin up myContainer2 without myContainer running.)
So what gives? I'm tempted to say the docker run "-dit
" options are what are making the difference here; that is the only difference I see between the docker run
and docker-compose
versions. I've been Googling for "How to set docker run options in docker-compose file" for an hour, but pulling up information that isn't applicable here. I'm clearly missing something fundamental. Anyone see what? Thank you.