My first target will be to create an Apache image that I can run on the Mac, and then transfer to the server on the Internet, and run there. So, let's go!
First, I pull an Ubuntu 14.04 image:
docker pull ubuntu:14.04
Resulting download is more than 200 MB large.
Then:
apt-get update
apt-get upgrade
apt-get install nano
apt-get install apache2
apt-get install php5 libapache2-mod-php5
apt-get install php5-mysql
An error message is displayed by the first two commands:
invoke-rc.d: policy-rc.d denied execution of start.
This page gives a solution: edit contents of /usr/sbin/policy-rc.d, to replace exit 101 by exit 0.
docker commit -m="Added Apache2" -a="<author>" \
<imageId> <userid>/apache2:v1
<imageId> is the id that was displayed by terminal prompt after the docker run -t -i ubuntu:14.04 /bin/bash command had been issued. <userid> can be the user id you registered on Docker Hub, if you did it, or another string.
Now, one way to test our containerized Apache server on the Mac is to use the docker run command first, to start a container based on our image:
docker run -t -p 80:80 -i <userid>/apache2:v1 /bin/bash
The -p option allows to map a machine port to the port used by the Apache server.
Then, from inside the container:
service apache2 start
Get the IP address to be used to reach the web server:
boot2docker ip
And then, using your preferred web browser, visit this IP address: you get the default Apache web page.
Now, let's go one step further. On the brand new server, where I just installed Ubuntu Server 14.04, I install Docker, as described in Docker documentation.
Then:
docker save -o apache2 <userid>/apache2:v1
docker load -i apache2
docker run -t -p 80:80 -i <userid>/apache2:v1 /bin/bash service apache2 start
That's it!