Friday, June 21, 2024

 Dockerize an Application (lab 9)


But Docker also gives you the capability to create your own Docker images, and it can be done with the help of Docker Files. A Docker File is a simple text file with instructions on how to build your images.

The following steps explain how you should go about creating a Docker File.

Step 1 − Create a file called Docker File and edit it using 

vi Dockerfile

Step 2 − Build your Docker File using the following instructions.

FROM ubuntu:latest
MAINTAINER Joe Ben Jen200@icloud.com
RUN apt-get update
RUN apt-get install -y nginx
ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]
EXPOSE 80






The following points need to be noted about the above file −

  • The first line "#This is a sample Image" is a comment. You can add comments to the Docker File with the help of the # command

  • The next line has to start with the FROM keyword. It tells docker, from which base image you want to base your image from. In our example, we are creating an image from the ubuntu image.

  • The next command is the person who is going to maintain this image. Here you specify the MAINTAINER keyword and just mention the email ID.

  • The RUN command is used to run instructions against the image. In our case, we first update our Ubuntu system and then install the nginx server on our ubuntu image.

  • ENTRYPOINT: Specifies the command which will be executed first

  • EXPOSE: Specifies the port on which the container is exposed

  • Once you are done with that, just save the file.
    Build the Dockerfile using the below command

Step 3 − Save the file. In the next chapter, we will discuss how to build the image

·                docker build -t kakrahanson-app .

·                $ sudo docker Images    # to show the docker image that was just built#



you have to run the following command
docker run -it -p port_number -d image_id

docker run -itd -p 9000:80 e916a9463607



Make sure port 9000 is open 

docker ps






No comments:

Post a Comment

  PROMETHEUS AND GRAFANA A robust performance monitoring and alerting stack is crucial to service reliability. Cloud Native Computing Foun...