In our example, we will use the Apache Web Server on Ubuntu to build our image. We should follow the steps given below, to build our web server Docker file.
Step 1 − The initial step is to build our Docker File. We should use vim and create a Docker File with the following data.
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 following points should be noted about the above statements−
Now that the file details have been entered, simply save the file.
Step 2 − Run the Docker build command to build the Docker file. It tends to be finished using the following command −
We are labeling our image as mywebserver. When the image is built, you will receive an successful message that the file has been built.
sudo docker build –t=”mywebserver” .
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
The following points should be noted about the above command −