0

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
Community
  • 1
  • 1
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
  • Is it to say that **the tutorial** is broken? – usr-local-ΕΨΗΕΛΩΝ Jul 17 '19 at 12:40
  • This tutorial guides you to use `service start` but this is something one would use in VMs. Containers are not VMs. More here: [systemd and systemctl within Ubuntu Docker images](https://stackoverflow.com/questions/39169403/systemd-and-systemctl-within-ubuntu-docker-images). Check the answer provided by [BMitch](https://stackoverflow.com/users/596285/bmitch) – tgogos Jul 17 '19 at 12:43
  • @usr-local-ΕΨΗΕΛΩΝ Possibly yes. – leopal Jul 17 '19 at 12:45

1 Answers1

1

A docker container needs a hold on a process to stay up.

When you run "service apache2 start", the service is started, and that's it, the container stops.

So you should use a command that keeps running, like : apachectl -D FOREGROUND

Loïc
  • 11,804
  • 1
  • 31
  • 49
  • 1
    What's the point of voting for closing as duplicate and then provide an answer? – leopal Jul 17 '19 at 12:54
  • @leopal as you said : it's a vote. Maybe it's not a duplicate, and in this case I have an answer... – Loïc Jul 17 '19 at 13:14
  • 1
    I answered to help questioner quickly identify a solution and then I would vote for closing as dup, but you did it for me. Anyway, I believe it is indeed a duplicate. – leopal Jul 17 '19 at 13:18