Answer the question
In order to leave comments, you need to log in
How to start a container via docker-compose.yml so that it doesn't stop immediately after creation?
There are 2 files in the folder:
1 file: docker-compose.yml
nginx:
build: ./
FROM centos
RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum -y install nginx
CMD nginx && bash
docker build -t img_nginx .
docker run --name cont_nginx -i -t img_nginx
docker-compose up -d --build
Answer the question
In order to leave comments, you need to log in
expected behavior. This is a docker feature. If the process terminates, then the container stops because its task is finished. If you want the container to work, then you need to start the service inside it, for example, just try it CMD ping 127.0.0.1
and then check if the container is running. docker-compose ps
In your case, you need to start nginx like this. You can CMD ["nginx", "-g", "daemon off;"]
connect to a running container like this docker exec -it NAME bash
, where NAME is the name of the container from docker-compose ps.
Better yet, style your docker-compose.yml properly
What does CMD ["nginx", "-g", "daemon off;"] mean in this case?
Is it possible to do the same for apache2 by analogy?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question