1

I have my LAMP stack installed already before Docker's. And I am using this image to build and run my Docker's LAMP stack:

$ docker pull linuxconfig/lamp

After all are downloaded and installed:

$ docker run -it linuxconfig/lamp /bin/bash
root@2e80dfd55a6e:/# service apache2 start
[....] Starting 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

So at my http://172.17.0.2/, I can see this default page:

enter image description here

But where can I locate its location so that I can put my PHP projects in there?

This the DockerFile from that image:

FROM linuxconfig/apache
MAINTAINER Lubos Rendek <web@linuxconfig.org>

ENV DEBIAN_FRONTEND noninteractive

# Main package installation
RUN apt-get update
RUN apt-get -y install supervisor libapache2-mod-php5 php5-mysql mysql-server

# Extra package installation
RUN apt-get -y install php5-gd php-apc php5-mcrypt

# Configure MySQL
RUN sed -i 's/bind-address/#bind-address/' /etc/mysql/my.cnf

# Include supervisor configuration
ADD supervisor-lamp.conf /etc/supervisor/conf.d/
ADD supervisord.conf /etc/supervisor/

# Include PHP Info page
ADD index.php /var/www/html/index.php

# Create new MySQL admin user
RUN service mysql start; mysql -u root -e "CREATE USER 'admin'@'%' IDENTIFIED BY 'pass';";mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;"; 

# Allow ports
EXPOSE 80 3306

# Start supervisor
CMD ["supervisord"]

EDIT:

$ sudo docker run --name=lamp -dP -v $PWD/html:/var/www/html linuxconfig/lamp
c2d1687aef21f8a12a7fbb31bf8cf71c1e5adabf381bc6d70e8804c6663f0bc0

And:

$ sudo docker port lamp
80/tcp -> 0.0.0.0:32769
3306/tcp -> 0.0.0.0:32768

I go to my browser at: http://172.17.0.2:32769/

I get this error:

enter image description here

Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

3

See if this article can help: "LAMP ( Linux, Apache, MariaDB, PHP ) stack Docker image deployment"

Save index.php file and within a new html directory.
Alternatively, html directory may contain your desired PHP application:

$ mkdir html
$ vi html/index.php
$ ls html/
index.php

At this stage we are ready to deploy “linuxconfig/lamp” docker image:

sudo docker run --name=lamp -dP -v $PWD/html:/var/www/html linuxconfig/lamp

That means you are mounting your host directory html into the linuxconfig/lamp container folder /var/www/html. (see "Mount a host directory as a data volume")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for the answer. I now get an error of `This site can’t be reached 172.17.0.2 refused to connect.` . please see my edit above. thanks. – Run Jan 08 '17 at 08:36
  • @teelou what is your OS? Windows? Linux? Mac? What docker are you using? a toolbox one based on VirtualBox? Or HyperV (Docker for WindowsX)? Or based on the XHyve VM? (Docker for Mac) – VonC Jan 08 '17 at 08:37
  • I'm on Linux Xubuntu 16.04. – Run Jan 08 '17 at 08:39
  • my docker - `$ docker --version Docker version 1.12.5, build 7392c3b` – Run Jan 08 '17 at 08:40
  • No VirtualBox is installed. – Run Jan 08 '17 at 08:40
  • @teelou Normal: on Linux, you don't need a VM to run Linux(!). Why do you access http://172.17.0.2:32769/? Why port 32769? Why not directly http://172.17.0.2? – VonC Jan 08 '17 at 08:41
  • bcos it gives me `80/tcp -> 0.0.0.0:32769` so I tot that is the address. – Run Jan 08 '17 at 08:45
  • @teelou did you try at port 80? I mean, in your question, when you see a page, you were visiting at port 80. – VonC Jan 08 '17 at 08:46
  • @teelou strange, considering the `/var/www/html/index.html` mounted as a volume should reflect your own `index.html` file, not the default one. – VonC Jan 08 '17 at 08:48
  • I have standard LAMP stack installed already at port 80. So I get the list of my standard LAMP stack projects that I keep there at http://127.0.0.1/ – Run Jan 08 '17 at 08:48
  • @teelou OK, I did not know that. So: regarding your container, can you try visiting at http://localhost:32769? And make sure your container is still running, with a docker ps. – VonC Jan 08 '17 at 08:52
  • aww yes I can see my project/ page at http://localhost:32769/ now. but not with the IP address. how come? – Run Jan 08 '17 at 08:55
  • 1
    @teelou You might have to ignore the 172.17.0.2 ip: it seems to be a generic message, also seen in http://stackoverflow.com/q/35165370/6309. localhost should be enough. – VonC Jan 08 '17 at 09:31
  • 1
    @teelou as seen here https://forums.docker.com/t/unable-to-access-docker-exposed-port-on-windows-machine/5865/4, 172.17.0.2 must be the IP of your container (which is Apache reports when it starts from said container), but from your host, you should use localhost only. – VonC Jan 08 '17 at 09:35
  • Thank you. 172.17.0.2 is generated by docker when I run this line `$ docker run -it linuxconfig/lamp /bin/bash` (check it out in my question above). – Run Jan 08 '17 at 16:22