Docker Compose keep container running

To keep a container running when you start it with docker-compose, use the following command

command: tail -F anything

In the above command the last part anything should be included literally, and the assumption is that such a file is not present in the container, but with the -F option (capital -F not to be confused with -f which in contrast will terminate immediateley if the file is not found) the tail command will wait forever for the file anything to appear. A forever waiting process is basically what we need.

So your docker-compose.yml becomes

version: '2'
services:
  my-test:
    image: ubuntu
    command: tail -F anything

and you can run a shell to get into the container using the following command

docker exec -i -t composename_my-test_1 bash

where composename is the name that docker-compose prepends to your containers.

Leave a Comment