Hosting a Website on Docker Using Apache


This page is a brief tutorial on how to host a website using Docker.

Step 1. Install Docker on your computer

This is as simple as heading to the Docker website and hitting the "Download" button. To verify your installation is working, run the command "docker run hello-world" in your shell once Docker is running.

...

Step 2. Pull the Ubuntu image from Docker

With Docker up and running, use the command "docker pull ubuntu" to run an Ubuntu image.

...

Step 3. Creating a container

Run the newly-installed Ubuntu image using "docker run -it ubuntu:latest /bin/bash" to start a new container and log into it.

Install apache and vim using the commands "apt-get install apache2" and "apt-get install vim" respectively.

Commit changes to the container using "docker commit (container ID) ubuntu-my_apache2". This creates a new Docker image using the container you just created.

...

Step 4. Sharing Data Between a Docker Container and Host

Use the command “docker run -it -p 127.0.0.1:80:80 -v H:\Docker_tutorial\local_dir: /var/www/html ubuntu-my_apache2 /bin/bash” to bind the container to a directory on your computer.

Step 5. Hosting your website on Docker

Either create a new HTML file or place pre-made HTML files into the linked directory. Use the command “/etc/init.d/apache2 restart” to start the apache service. Access the listed IP using your web browser and you should now have your website successfully hosted.

...