Day 17 : Docker Project for DevOps Engineers.

Day 17 : Docker Project for DevOps Engineers.

A Dockerfile serves as a blueprint for creating Docker images, allowing us to automate the image-building process. By encapsulating each step within the Dockerfile, we can streamline the creation of our images with a single command. Here are some essential commands commonly utilized in a Dockerfile:

  1. FROM: Establishes the foundational base image for our custom image, providing a starting point for further modifications.
  2. RUN: Executes commands within the image during the build process, enabling tasks such as package installations or setup procedures.
  3. COPY: Transfers files from the host machine to the image, facilitating the inclusion of necessary resources or configuration files.
  4. ENV: Defines environment variables within the image, allowing for configuration and customization of the runtime environment.
  5. EXPOSE: Specifies the ports that the container should expose, enhancing communication between the container and the external world.
  6. CMD: Sets the default command to be executed when the container is launched, providing flexibility in defining the primary behavior of the container.


__________________________________________________________________________________


Tasks:


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


Python application cloned: https://github.com/mosad2/docker-projects-.git



The steps to run the application locally are explained in the above link. I am just creating the dockerfile for the same steps.

Dockerfile:

FROM python:3.9-slim-buster

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY app.py .

EXPOSE 5000

CMD ["python", "app.py"]
        

2. Build the image using the Dockerfile and run the container.

Build the image -

docker build . -t mosad7/myqouta-app         


Run the Container -


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


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

Firstly, I renamed the image to push in my docker hub repo.

sudo docker tag old:tag new:tag        


Now, while pushing I got access denied so I first logged in and then pushed the image.

sudo docker login
sudo docker push imagename        


The image is successfully pushed.



要查看或添加评论,请登录

Mosad Rashad的更多文章

社区洞察

其他会员也浏览了