Deploying Apache Web Server & Python On A Docker Container

Deploying Apache Web Server & Python On A Docker Container

This is a brief tutorial / walkthrough for:

  • Deploying Apache Web Server on a Docker container
  • Installing and Using Python on a Docker container

Deploying Apache Web Server on a Docker Container

Step 1: Pull CentOS 6 image from the Docker hub by typing docker pull centos:6

No alt text provided for this image

Step 2: Launch a container with CentOS 6 image by typing docker run -dit --name <your_container_name> centos:6

Step 3: Install Apache web server on the newly launched container by typing docker exec <your_container_name> yum install httpd -y

No alt text provided for this image

Step 4: Start the httpd service by typing docker exec <your_container_name> service httpd start

No alt text provided for this image

Step 5: Check if the web server is working by visiting the Local IP of the Docker container, which is 172.17.0.2 in this case. The page shown below is the default landing page provided by Apache.

No alt text provided for this image

Step 7: Create index.html file to customize the landing page on your own. This can be done by attaching the container to shell by typing docker attach <your_container_name> and creating a custom index.html file in the document root /var/www/html using vi / vim / your preferred CLI text editor.

No alt text provided for this image

Finally, we can test our website using the Local IP of the container, which appears as below in this case:

No alt text provided for this image


Installing and Using Python on a Docker container

Here, I'll be using the latest version of CentOS, i.e., CentOS 8.

Step 1: Launch a container using your desired container name and centos as the image. By not specifying the version, the latest version of the image will be downloaded from the Docker hub and will be used for our container.

Step 2: Install the python3 package by typing docker exec <your_container_name> yum install python3 -y

No alt text provided for this image

Step 3: Attach the container to the shell and create a custom .py file to test Python in the container. Once created, run the file by type python3 <file_name>.py in the container's bash prompt.

No alt text provided for this image


And that's it!


To view or add a comment, sign in

More articles by Abhinav Sinha

Others also viewed

Explore content categories