Docker Project for DevOps Engineers part-II

Suraj barikSuraj barik
3 min read

Dockerfile instruction 🦈🍥

Dockerfile is a text file containing various instructions and configurations in the form of commands. Dockerfile helps to build a Docker image.

📝DockerFile Syntax:

FROM

:[taking base image from Docker Hub]

WORKDIR /app

:[Set the working directory in the container]

COPY . /app

:[Copy the current directory contents into the container at /app]

RUN

[Install any needed packages specified in requirements.txt for building the image]

EXPOSE

[Make port available to the world outside this container]

CMD

[Run specified command when the container launches]

📌Task:

✔️The task is to create a Dockerfile for a simple web application.

Create a project directory on your ec-2 instance and clone the git repo where the node-to-do-app source code is present

Fork this repository to get started:https://github.com/surajc5/node-todo-cicd.git

✔️Build the image using the Dockerfile and run the container

-Write a Docker file in the project directory to build a Docker image for the application

-Docker file created then Build the image using Dockerfile

💡
1. Must be Install docker in your system using

💡
2. Must grant access to the user they want to use to interact with docker and run docker commands.

💡
If still facing the same grant permission error then Reboot the system

-Built docker image by running the command docker build . -t <tag-name>

-To create a container from docker Image, run the command :
[docker run -d -p 8000:8000 node-todo-app:latest]

-To check the running container [ docker ps -a]

✔️Verify that the application is working as expected by accessing it in a web browser

-As we can see that port 8000 running so ,go to ec2 Instance and acess the 8000 given as follows

BOOM✨🎇🎇✨🎇🎇✨ BOOM🎉🎉

✔️Push the image to a public or private repository (e.g. Docker Hub )

  • Before pushing image from the source to the destination or docker hub u need to modify the image name with dockerhubuser name /new name

      #sudo docker tag <Exiting images name > dockhubUsername/New Image name
      Sudo docker tag node-todo-app surajdev5/node-todo-app
    

-Login into your docker registry using docker login command from the ec2 instance

-Push your image to the docker hub:

✔️Let's see how to push the image to a public or private repository (e.g. Docker Hub )

BOOM✨🎇🎇✨🎇🎇✨ BOOM🎉🎉

Thanks for reading my article. Have a nice day. Happy Learning:)😊😊

For updates follow me on LinkedIn: Suraj Barik

0
Subscribe to my newsletter

Read articles from Suraj barik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj barik
Suraj barik

I'm Suraj Barik Aspiring DevOps Engineer with Hands-on experience in Automating,Shell Scripting, Supporting in AWS, management, CI/CD, and DevOps processes.