Create test Apache site with Docker

This tutorials shows steps on how to run docker and setup a test Apache site using a docker image. This tutorial aims to introduce the basic operation of docker and how to use it on a Linux environment.

1. Connect to your EC2 Ubuntu instance via SSH.

2. Run apt update to get the latest package definitions.

 # apt update  

3. Install docker.io package using apt.

 # apt install docker.io 

4. After installing docker, use docker search to search for the Apache docker image.

#  docker search apache 

5. Download the Apache docker image using docker pull.

#  docker pull apache 

6. View all your available docker images using the docker image command.

#  docker images 

7. Create and run a docker container based on the Apache image

# docker run -itd --name=apache --hostname=webserver -p 80:80/tcp httpd 

where:

-itd = interactive, tty allocated, detach run

-p = publish port (container port):(host port)/protocol

–name = new container name

–hostname = new container hostname

8. Check the running docker containers.

# docker ps 

9. Go to a web browser and type on the URL tab the Public IP address of your EC2 instance. You should see the apache test page ” It works!”.

10. To modify this page, connect to this docker container using docker exec command.

# docker exec -it apache /bin/bash 

11. Navigate to the apache doc root to modify the index.html file.

# cd /usr/local/apache2/htdocs 

12. Update the index.html file using the echo command.

# echo "This is my test website. - masterkenneth" > index.html 

13. You can exit from docker by just using the exit command

# exit

14. Now refresh your Webpage and confirm that you have updated your webpage.

This is just a very simple test and introduction to docker. Docker has more features that are just waiting to be explored.

————————————————

– masterkenneth

Leave a Reply

Your email address will not be published. Required fields are marked *