Docker Community Forums

Share and learn in the Docker community.

Reproducing steps from simple Dockerfile - Beginner

(Baemar06) #1

Hi there.
I am currently getting into the Docker Topic and got stuck while trying to reproduce the steps from the Dockerfile form this Tutuorial on Amazon Web Services

I have already gone through the steps and at the end it worked for me when I ran the Dockfile. But since I am trying to learn to get more into the topic I wanted to reproduce every single line from the dockerfile.

So, again… here is the content of the Dockerfile:

[ec2-user ecs-demo-php-simple-app]$ cat Dockerfile
FROM ubuntu:12.04

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y git curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql

# Install app
RUN rm -rf /var/www/*
ADD src /var/www

# Configure apache
RUN a2enmod rewrite
RUN chown -R www-data:www-data /var/www
ENV APACHE_LOG_DIR /var/log/apache2


CMD ["/usr/sbin/apache2", "-D",  "FOREGROUND"]

and here is what I have tried to get to the same result:

$ Docker pull Ubuntu:latest
$ Docker run –i –t –d Ubuntu

$ docker exec CONTAINER-ID apt-get update –y
$ docker exec CONTAINER apt-get install -y git curl apache2 php5 libapache2-mod-php5 php5-mysql
$ docker exec CONTAINER rm -rf /var/www/*
 #For the next step I cd'ed on my local machine into the folder I downloaded from the hub in the tutorial
$ docker cp src CONTAINER-ID :/var/www
$ docker exec CONTAINER-ID a2enmod rewrite
$ docker exec CONTAINER-ID bash -c "cat /etc/apache2/apache2.conf"
# and just for testing
$ docker exec CONTAINER-ID bash -c "curl http://localhost" docker exec 
$ docker exec CONTAINER-ID netstat -tulpn | grep :80

At the end, the server seemed to be up and the port 80 was open.
However, I couldn’t reach the searcher via my web browser like I could when I ran the original Dockerfile.
I am running the toolbox on Win10 x64

I think that there is a problem with mapping the ports from the container and the VM what do you think?
I saved the container and tried to run it with

docker run -d -p 2376:80 apache/php /usr/sbin/apache2ctl -D FOREGROUND

since 2376 was the port from my VM. I also tried 9999 instead for the localhost.

Can anyone help me solving this problem?

By starting the container with
docker run -d -p 80:80 apache/php /usr/sbin/apache2ctl -D FOREGROUND

I can now reach the default APAChE2 page. However, in previous steps it should have replaced the index.html with the index.php from the tut right?

(Jeff Anderson) #2

So you are launching a container, running a bunch of commands that install software and start a webserver using docker exec.

The docker run line that you referenced does not include the same port publishing line that your other docker run command has:

docker run -d -p 80:80 ...

The -p 80:80 says to take connections to the host’s port 80, and forward them on to the container’s port 80. (it’s -p hostport:containerport)

If you repeat the exercise while including that line, I suspect it will work.



Once you have your container running, I would recommend simply running:

docker exec CONTAINER-ID bash

Then check the configuration of everything in the container to see if it is what you are expecting based on the previous commands you ran, specifically the index.php vs index.html piece you’re stuck on.

Also, you could fire up a container from the Dockerfile along side the “step-by-step” container so you could look at them both at the same time. Just be sure to map the ports differently for each one.

(Baemar06) #4

hey, thanks for your reply.

I have tried it and it partly works.
I get to the default Webserver page saying:

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

But I don’t see the php file being run.

also I don’t know I can reproduce the steps
ENV APACHE_LOG_DIR /var/log/apache2

can anyone tell me what is being done her and how the lines could look like if I wanted to do this outside of a dockerfile manually?