1: Configuring the Webserver On a Docker Container
In this article, we will be discussing about how to install and configure HTTPD WebServer on a Docker Container Image
For this tutorial, I have launched an instance in AWS Cloud. The Instance Image is Amazon Linux 2. On the top of it, I installed docker using "yum install docker" command. As the repo's are already configured in Amazon Linux, it will directly be downloaded and installed.
[root@ip-172-31-40-189 ~]# docker --version
Docker version 19.03.13-ce, build 4484c46
After the docker is installed, we will now build an image using Dockerfile.
The Dockerfile looks like this
- FROM centos:latest
- RUN yum install httpd -y
- CMD /usr/sbin/httpd
- expose 80/tcp
- COPY workspace/html_files/index.html /var/www/html/
For building the image, we simple need to go to the directory where Dockerfile is located and run the following command:
docker build . -t httpd:v1
This will create an image named "HTTPD" and version/tag as "v1"
We now just need to create a container using this image, everything is already specified in the Dockerfile. NOTE: while running the image we need to assign the webserver port to the host OS with the help of -p option.
- docker run -it -p 8080:80 --name myweb1 httpd:v1
This will create a container and run the container with the specification in the Dockerfile.
And now you can simple type hostip:8080 in any web browser and you can see the content available in the index.html file
Content in the Index.html file:
Thus we have successfully setup webserver running on a docker container os
2: Setup Python Interpreter on a Docker Container
For this we simple need to create an image(im using centos:7) and install Python using yum command (or we can also specify this in the Dockerfile using CMD yum install python3 -y)
The command to run in Container is:
yum install python3
We can run everything on python just as we do with python in a regular OS