5

I am new to Docker. My Dockerfile (got from a tutorial) is:

FROM ubuntu

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends apache2 \
                        libapache2-mod-jk
VOLUME ["/var/log/apache2"]
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
EXPOSE 80 443

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]

I gave docker build -t mg:httpd apache\. No errors.

λ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                SIZE
mg                  httpd               262d7a4f85fc        About an hour ago      248MB

docker run -it mg:httpd

No errors, but the cursor returns to command prompt immediately. Getting Unable to connect on taking http://localhost/ in browser.

λ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS                
600231bbd461        mg:httpd            "apache2ctl -D FOR..."   2 minutes ago       Exited (0) 2 minutes ago             

docker logs is empty

λ docker events
2017-09-08T15:26:10.726720800+05:30 container create 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:10.740310700+05:30 container attach 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:11.035777100+05:30 network connect 2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, name=bridge, type=bridge)
2017-09-08T15:26:11.090873500+05:30 volume mount e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, destination=/var/log/apache2, driver=local, propagation=, read/write=true)
2017-09-08T15:26:11.548736900+05:30 container start 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:11.573272300+05:30 container resize 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (height=41, image=mg:httpd, name=zealous_ritchie, width=168)
2017-09-08T15:26:12.733164900+05:30 container die 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (exitCode=0, image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:13.227455500+05:30 network disconnect 2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, name=bridge, type=bridge)
2017-09-08T15:26:13.306885700+05:30 volume unmount e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, driver=local)

what could be the reason? How can I look into the apache log\conf files when the container is not started?

Shoreki
  • 1,057
  • 4
  • 14
  • 33

2 Answers2

3

So your Webserver is not startet as a foreground process, that is why the container is stopped immediately.

I think you should change

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]

to

CMD ["apache2ctl", "-D", "FOREGROUND"]

Because you want that command to run when the container is mounted.

The ENTRYPOINT directive declares the executable which is used to execute the CMD.

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]
results in:
$  apache2ctl -D FOREGROUND <command either from the run command line or the CMD directive>

The default command from Ubuntu image I could find is /bin/bash. So when you run the container using:

docker run -it mg:httpd

the resulting command that is executed will be:

$  apache2ctl -D FOREGROUND /bin/bash

what obviously does not make much sense. I would recommend to go over that post, it explains the details very well.

After the change described above it will look like that:

(default) ENTRYPOINT ["/bin/sh", "-c"]
CMD ["apache2ctl", "-D", "FOREGROUND"]
what results in:
$  /bin/sh -c "apache2ctl -D FOREGROUND"
philipp
  • 15,947
  • 15
  • 61
  • 106
0

This happens when you run the container interactively because that allows the SIGWINCH signal to be forwarded from the host to the container. SIGWINCH is used by Apache to signal a graceful shutdown. I provided a full answer here.

Sam Herrmann
  • 6,293
  • 4
  • 31
  • 50