We need to
- install apache2 on the container
- start it
- access its port (80)
Now things get a bit complex: remember that on a Mac we need to run a VirtualBox to have a Linux VM onto which docker acts. So we need the container to expose the port to its host (VirtualBox), and VirtualBox has to expose it to the Mac. To find out the IP address of VirtualBox, we execute
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.2
and we discover that the Mac sees the VirtualBox as 192.168.99.100: so this is the address we’ll need to use to access our Apache once that’s installed.
As a first step, when we activate the container onto which we want to install apache2, we need to make the port 80 visibile from the host machine
docker run --name myLinux2 -p 0.0.0.0:8000:80 -it ubuntu:latest bash
The switch -p 0.0.0.0:8000:80 maps the port 80 in the container to port 8000 exposed by the VirtualBox on the host machine: so now we have the full info about where to find Apache once that’s installed: it will be on 192.168.99.100:8000.
NOTE: it is really important that we use 0.0.0.0.on a Mac. If we had a Linux PC instead, we’d use 127.0.0.1, and to see the page from the browser we’d use localhost:8000.
The rest is easy. On our running “myLinux2” container we just need install Apache, so (after the usual to execute apt-get update and apt-get –y upgrade that we found in Tutorial 1) we execute
apt-get install -y apache2
Once it is done, we need to start it.
then we run a browser on our Mac pointing at 192.168.99.100:8000, et voilà, we get the standard home page.
WATCH OUT: it is apache2ctl, NOT apachectl (since we’ve installed the most recent Apache versione: 2.4).
We’ll need to do some customization. Surely we want to customize the directory where we serve from, and most likely also the Apache configuration.
That is simply done, by using the file system sharing we introduced in Tutorial 5.
As we had to plan in advance that we wanted to share a port, and we declared it when starting the container, we’ll have to plan in advance the file system sharing.
So we’ll need to add to the docker run command the following switch:
if we keep the default, that the web home directory is /var/www/html.
If we want to change the something in the configuration, we can do it inside the container (editing the files in /etc/apache2/) , or outside, by preparing a mapping of the files we want to change onto our host machine file system.
All this was done by hand. Of course it is much more practical to do it via Dockerfile, and this is what we are going to discuss in next tutorial.