Make sure Docker daemon is running
sudo service docker start
Build Docker image
sudo docker build -t louwii/wordpress-test-1 .
-t
specify a name for that image so we can find it easily Name and optionally a tag in the 'name:tag' format
Start the image
docker run \
-d \
-p 8080:80 \
-v $(pwd)/src:/var/www/html \
-v $(pwd)/src/vhost.conf:/etc/apache2/sites-enabled/vhost.conf \
louwii/wordpress-test-1;
-d
to run it in the background-p
map the port 8080 of the hosting machine to the port 80 of the container-v
to mount a folder of the hosting machine to a folder on the container The first is loading our local virtual host config into the container Apache folder The second is setting pointing our local code files to the default directory of the container Apache server (default Apache folder)
For a better, self controlled setup, we can do:
docker run \
-d \
-p 8080:80 \
-v $(pwd)/src/server-conf/mysite.conf:/etc/apache2/sites-enabled/mysite.conf \
-v $(pwd)/src/mysite:/var/www/mysite \
louwii/wordpress-test-1;
mysite.conf
would have DocumentRoot /var/www/mysite
to make it point to our code files.
Check if it's up
docker ps
The result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1b5e98a5893 louwii/wordpress-test-1 "apache2-foreground" 14 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp tiny_cray
Check in the browser, something should load ! localhost:8080
Get a shell
docker attach [CONTAINER ID]
But your image might not have a shell instance, so this next command is handy (Docker >= 1.3)
docker exec -i -t [CONTAINER ID] /bin/bash
or
docker exec -i -t [CONTAINER NAME] /bin/bash
Type exit
to exit the shell.
Stop and delete
docker stop [CONTAINER ID]
docker rm [CONTAINER ID]
If you only stopped a container, you can start it again with docker start [CONTAINER ID]
To list all containers, even the stopped ones, use docker ps -a
Make local Apache2 to point to the container
Be sure you have enabled all required Apache modules :
sudo a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html
Use a virtual host configuration like this one:
<VirtualHost *:80>
ServerName mysite.dev
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
CustomLog /var/log/apache2/docker_apache_proxy_https_access.log combined
ErrorLog /var/log/apache2/docker_apache_proxy_https_error.log
</VirtualHost>
In you /etc/hosts
file, add this line :
127.0.0.1 mysite.dev
Then in your browser, go to mysite.dev
and you should be able to see your site from the Docker container.