I am following a tutorial about Docker. I run on Windows, so I already installed Docker for Windows and signed up for the Hub.
Currently I am in the process of creating my very first Apache instance on Docker.
Following the tutorial, I created the very first Dockerfile of a debian
derivative and ran the container. My output was consistent with the tutorial (>
denotes Windows prompt)
> docker run -it --name mydebian_container mydebian
root@ef9eb174874a:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 02:43 pts/0 00:00:00 bash
root 9 1 0 02:43 pts/0 00:00:00 ps -ef
Then I followed the tutorial on running Apache from the container
Dockerfile
FROM debian
RUN apt-get update &&\
apt-get -y install procps libapache2-mod-php
CMD service apache2 start
Cool, yea? But when I run the container nothing happens, and the container itself exits successfully
D:\IdeaDevOps\dockers\apache2>docker run -it --name apache2 -v d:\IdeaDevOps\dockers\apache2:/var/www/html debian_apache2
[....] Starting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
. ok
>docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09d5b4b3fa49 debian_apache2 "/bin/sh -c 'service…" 24 seconds ago Exited (0) 22 seconds ago apache2
8d1c4522aa30 mydebian "bash" 2 hours ago Exited (0) 2 hours ago elated_wing
ae769d388b36 ubuntu "bash" 2 hours ago Exited (0) 2 hours ago kind_murdock
5596841696f6 mydebian "bash" 2 hours ago Exited (0) 2 hours ago festive_booth
I really can't figure why it fails to keep a running Apache server. AH00558
is a warning, it never blocks Apache from starting up.
I have a running instance of Apache 2.4 on my laptop listening on 80, so I stopped the Windows service relative to it.
I also tried to change the port bindings in Docker, or to not pass any port binding (-p
) to Docker to see what happens.
As you can see, I am not running the container -d
on purpose (unlike the linked tutorial) to see its output.
What is preventing the Apache-based container to start? I am not really interested in running a real Apache/php, but I just want to get acquainted with Docker and how to customize an image for your needs. TL;DR I am learning, do not have a real business need now.
Update
I tried to use a hammer of Thor approach. If I insisted in doing docker start apache2
I can get the Apache server alive for a few seconds only, just the time to browse the root directory on my browser. The server ends eventually
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker start apache2
apache2
D:\IdeaDevOps\dockers\apache2>docker exec apache2 bash
D:\IdeaDevOps\dockers\apache2>docker exec apache2 bash
D:\IdeaDevOps\dockers\apache2>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c669aacbed7a debian_apache2 "/bin/sh -c 'service…" 20 minutes ago Up 17 seconds 0.0.0.0:80->80/tcp apache2
D:\IdeaDevOps\dockers\apache2>docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c669aacbed7a debian_apache2 "/bin/sh -c 'service…" 20 minutes ago Exited (1) 1 second ago apache2
8d1c4522aa30 mydebian "bash" 2 hours ago Exited (0) 2 hours ago elated_wing
ae769d388b36 ubuntu "bash" 2 hours ago Exited (0) 2 hours ago kind_murdock
5596841696f6 mydebian "bash" 2 hours ago Exited (0) 2 hours ago festive_booth
D:\IdeaDevOps\dockers\apache2>docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c669aacbed7a debian_apache2 "/bin/sh -c 'service…" 21 minutes ago Exited (1) 23 seconds ago apache2
8d1c4522aa30 mydebian "bash" 2 hours ago Exited (0) 2 hours ago elated_wing
ae769d388b36 ubuntu "bash" 2 hours ago Exited (0) 2 hours ago kind_murdock
5596841696f6 mydebian "bash" 2 hours ago Exited (0) 2 hours ago festive_booth