Docker Community Forums

Share and learn in the Docker community.

Why apache container does not persist after starting with service command

(Danielinclouds) #1


I have 2 docker images:
FROM ubuntu:latest
MAINTAINER John Smith ""

RUN apt-get update
RUN apt-get install -y apache2

ENTRYPOINT ["/usr/sbin/apache2ctl", “-D”, “FOREGROUND”]

FROM ubuntu:latest
MAINTAINER Daniel1 Kozlowski ""

RUN apt-get update
RUN apt-get install -y apache2

ENTRYPOINT ["/usr/sbin/service", “apache2”, “start”]

Can someone explain me why first image persists after creating container and second one is not?
I use below command to start container:
docker run -d myimage

(Eriksenonline) #2

systemd is not enabled by default in ubunu I beleve.
In centos I have to prepare the system for systemd use like this example:

Then when you look at You will see the systemctl enable httpd.service that is started by the CMD ["/usr/sbin/init"]

So when you do
ENTRYPOINT ["/usr/sbin/service", “apache2”, “start”] I think it just try to run the command and fails. When it fails the container go down.

(Danielinclouds) #3

Why do you need to remove all these files?

(Eriksenonline) #4

I realy do not know it is just how Centos works

(David Maze) #5

Look at the screen shot on Do you want to do all of these things, just to launch a Web server? Can you do all of these things in a Docker environment?

If you try to use systemd in a Docker container, you need to go out of your way to tell systemd to not do a bunch of things it would need to do on a bare-metal system (or a full-blown VM), and also give the container some extra privileges (IIRC it’s very hard to not tell systemd to not do cgroup management, even though Docker and the host’s init system are doing it already).

Your first Dockerfile, that just runs apachectl -k start -DFOREGROUND directly, is much better than trying to understand the previous paragraph. (As the previous poster noted, your second Dockerfile tells the init system to start Apache, but (a) there’s no init system running so this doesn’t do anything, and (b) the start command returns immediately and when the CMD returns the container exits.)