✌️Day 17✌️ ✍️Docker Project for DevOps Engineers✏️

·

4 min read

✌️Day 17✌️
✍️Docker Project for DevOps Engineers✏️

☸️Today's challenge is so special Because we are going to do a DevOps project today with Docker🐋

🐋🐋What is Dockerfile?

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.🍃🍃

👨🏻‍💻Task🛠️🚧👨‍💻

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

  • Build the image using the Dockerfile and run the container

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

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

📝Steps :- 📜

1. Launch the VMWare application and work in Ubuntu OS.

2. Clone the repository from GitHub to your Ubuntu server using the command.

3. Go to react_django_demo_app directory.

4. Create a Dockerfile with the help of vim command.

🍃🍃The first thing we need to do is define from which image we want to build from.

🍃🍃Here we will use the python:3.9 image available from the Docker Hub.

FROM python:3.9

🍃🍃Next, we create a directory to hold the application code inside the image, this will be the working directory for your application:

WORKDIR /app

🍃🍃Copy your application's code inside the Docker image folder app using COPY instruction:

COPY . /app

🍃🍃This command installs all the dependencies defined in the requirements.txt file into your application within the container:

RUN pip install -r requirements.txt

🍃🍃This command releases port 8000 within the container, where the Django app will run:

EXPOSE 8000

🍃🍃This command starts the server and runs the application:

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

5. Build an Image using Dockerfile📜

🍃🍃To build an image using Dockerfile,
build is the command to create an image from the file.
Go to the directory that has your Dockerfile and run the following command


docker build -t <image-name>  .

Now you can see that the python:3.9 image is being pulled from where, our DockerHub.
If I want to run the container, what should I do first if I want to run the container?
I want an image, I want a docker image. How is the image created, the image is created from the Docker file.

🎯Now, we can see 6 steps.
Why are these 6 steps, because there are only 6 lines in our docker file, if our Dockerfile had 15 lines, then 15 steps would have been shown here.

🎯Every line in a docker file is a building steps.

🍃🍃By using docker images command, we can see the list of images.

🚫Docker has not been created yet, that's why no container is being shown on the giving docker ps command.

🚫Docker has not yet been created because the container has not yet been run. so we will now run the container.

6. Run the image to create a container

Running your image with -d runs the container in detached mode, leaving the container running in the background. The -p flag redirects a public port to a private port inside the container and - - name flag for assigning name to docker container.

🍃🍃Run the image you previously built:

docker run -d --name <container-name> -p 8000:8000 <image-name>

🍃🍃docker ps command is used to list all the containers.

🍃🍃Now, see the container is running.

6.Verify that the application is working as expected by accessing it in a web browser.
🍃🍃Go to your web browser, put the URL with the port number, and search.

http://ubuntu-public-ip:8000

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

  • Login to the docker hub portal.

    • Push docker image to docker hub using command :-

    • docker push <image-name>

      📚📖📝Feel free to ask me, if you need any help regarding this docker project📚📖📝

      ❄Thank you for reading! I hope you find this article helpful❄

      ❄❄❄❄❄❄The End❄❄❄❄❄❄❄

      ###