#Day17 : Docker Project for DevOps Engineers.

#Day17 : Docker Project for DevOps Engineers.

Docker is a tool that makes it easy to run applications in containers. Containers are like small packages that hold everything an application needs to run. To create these containers, developers use something called a Dockerfile.

A Dockerfile is like a set of instructions for making a container. It tells Docker what base image to use, what commands to run, and what files to include. For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.

Tasks

Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)

Step1:

Clone a repository having a simple app from github. Go inside the projects folder and use command:

git clone <URL>

you will find the repository in your projects folder:

go inside the folder using

cd <folder name>

Check the main file which has to be run is in which format (eg : python, nodejs)

Now create a file named Dockerfile

Open the file in vim and type the following:

FROM python:3.9

COPY . .

RUN pip install -r requirements.txt

CMD ["python","manage.py","runserver","0.0.0.0:8000"]

The requirements.txt file contains the required dependencies for the file to run

Your Docker file is ready to build an image.

Build the image using the Dockerfile and run the container

To create an image from it, run the following command:

docker build -t <image_name:latest> .

To run a container from the built image:

docker run -d -p 8000:8000 <imagename>

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

To access it in a web browser, we need to first enable the port specified in the security group attached to the instance.

Now copy the public IP add:<port number>

and paste it in browser.

Congratulations your docker container is up and running !

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

To tag repository first, use command:

docker tag <image_name:tag> <repo_name:tag>

Log in to docker

docker login

Enter credentials used for the docker hub account

now you can push using the following code:

docker push <repo_name:tag>

Your image is now pushed onto docker hub: