Whenever I try docker-compose up -d
, my container exits with code 0
.
I have following docker-compose.yml
:
version: "3"
services:
ansible:
container_name: controller
image: centos_ansible
build:
context: centos_ansible
networks:
- net
networks:
net:
The Dockerfile inside centos_ansible
:
FROM centos
RUN yum install python3 -y &&
yum install epel-release -y &&
yum install ansible -y
3
Answers
To keep your container running, you need to tell it to do something.
You can do this, as another answer mentioned, by adding an
ENTRYPOINT
to your Dockerfile. Alternatively, from this answer, you can add a command like this, or do something more useful:Or if you’ll need get a shell into the container, you can add the
tty: true
option to your service.Your docker container only keeps running if there is something to run inside your container. Try adding an
ENTRYPOINT
to your Dockerfile! (https://docs.docker.com/engine/reference/builder/#entrypoint)The problem is that you do not specify nothing to do to your container and, as a consequence, it exits immediately.
You have several ways to tell the container what to do. Please, see this great SO question for further information.
As you are using docker compose, you can indicate the
command
the container must execute:It seems you are trying to run
ansible
from docker. Please, see this article, perhaps it will give you some additional ideas for your problem.