Building a web Server Docker File

Last updated on Sep 16 2022
Neha Warghade

Building a web Server Docker File

Docker – Building a Web Server Docker File

We have already learnt how to use Docker File to build our own custom images. Now let’s see how we can build a web server image which can be employed to build containers.

In our example, we are going to use the Apache Web Server on Ubuntu to build our image. Let’s follow the steps given below, to build our web server Docker file.

Step 1 − The primary step is to build our Docker File. Let’s use vim and create a Docker File with the subsequent information.

FROM ubuntu RUN apt-get update RUN apt-get install –y apache2 RUN apt-get install –y apache2-utils RUN apt-get clean EXPOSE 80 CMD [“apache2ctl”, “-D”, “FOREGROUND”]

The subsequent points need to be noted about the above statements −

  • We are primary creating our image to be from the Ubuntu base image.
  • Next, we are going to use the RUN command to update all the packages on the Ubuntu system.
  • Next, we use the RUN command to install apache2 on our image.
  • Next, we use the RUN command to install the necessary utility apache2 packages on our image.
  • Next, we use the RUN command to clean any unnecessary files from the system.
  • The EXPOSE command is employed to expose port 80 of Apache within the container to the Docker host.
  • Finally, the CMD command is employed to run apache2 within the background.
  • doc 1

Now that the file details have been entered, just save the file.

Step 2 − Run the Docker build command to build the Docker file. It can be done using the subsequent command −

sudo docker build –t=”mywebserver” .

We are tagging our image as mywebserver. Once the image is built, you’ll get a successful message that the file has been built.

doc 2

Step 3 − Now that the web server file has been built, it’s now time to create a container from the image. We can do this with the Docker run command.

sudo docker run –d –p 80:80 mywebserver

doc 3

The subsequent points need to be noted about the above command −

  • The port number exposed by the container is 80. Hence with the –p command, we are mapping the same port number to the 80 port number on our localhost.
  • The –d option is employed to run the container in detached mode. This is so that the container can run within the background.

If you go to port 80 of the Docker host in your web browser, you’ll now see that Apache is up and running.

doc 4

So, this brings us to the end of blog. This Tecklearn ‘Building a web Server Docker File’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:
https://www.tecklearn.com/course/devops-training/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

0 responses on "Building a web Server Docker File"

Leave a Message

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