Day17 of #90DaysOfDevOps Challenge

Day17 of #90DaysOfDevOps Challenge

Dockerfile:

Instead of manually creating docker images by running multiple commands one by one, we can write a script where we can specify everything required for our image, and run one command to build the whole image.

Each command in dockerfile adds layers to create a docker image.

Here are some of the most commonly used commands in a Dockerfile:

  • FROM: Specifies the base image required for our new image.
  • RUN: Executes a command in the image during the building of the image, like installing packages.
  • COPY: Copies files from the host machine to the image.
  • ENV: Sets an environment variable in the image.
  • EXPOSE: Specifies the ports that should be exposed on the container.
  • CMD: Executed by container by default, when we launch the image to run 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/shreys7/django-todo

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

RUN pip install Django==4.2.2

COPY . .

RUN python manage.py migrate

CMD ["python", "manage.py", "runserver", "0.0.0.0:8005"]        
No alt text provided for this image

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

Build the image -

docker build . -t todo-app        
No alt text provided for this image

Run the Container -

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image

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        
No alt text provided for this image

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

sudo docker login
sudo docker push imagename        
No alt text provided for this image
No alt text provided for this image

The image is successfully pushed.

No alt text provided for this image

Thank you for reading! ??


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

Aishwarya keshri的更多文章

  • Day26 of #90DaysOfDevOps Challenge

    Day26 of #90DaysOfDevOps Challenge

    Jenkins Pipeline: Jenkins Pipeline is a suite of plugins that supports implementing and integrating continuous delivery…

  • Day24 of #90DaysOfDevOps Challenge

    Day24 of #90DaysOfDevOps Challenge

    ??Project: Containerise and deploy a node.js application using Jenkins Job.

  • Day23 of #90DaysOfDevOps Challenge

    Day23 of #90DaysOfDevOps Challenge

    CI/CD Continuous integration and continuous delivery help in automating the software development lifecycle stages…

    2 条评论
  • Day22 of #90DaysOfDevOps Challenge

    Day22 of #90DaysOfDevOps Challenge

    ??Jenkins Jenkins is an open-source tool that helps in creating pipelines and automating the software development…

  • Day21 of #90DaysOfDevOps Challenge

    Day21 of #90DaysOfDevOps Challenge

    Important interview questions and Answers for Docker: 1. What is the difference between an Image, Container and Engine?…

  • Day20 of #90DaysOfDevOps Challenge

    Day20 of #90DaysOfDevOps Challenge

    Docker Cheat Sheet: ??Docker images- Show all locally stored top-level images: docker images Pull an image from a…

  • Day 19 of #90DaysOfDevOps Challenge

    Day 19 of #90DaysOfDevOps Challenge

    Docker Volumes When we are working on docker, the data we store gets lost when the container is destroyed. So, to…

    2 条评论
  • Day 18 of #90DaysOf DevOps Challenge

    Day 18 of #90DaysOf DevOps Challenge

    ?Docker Compose Using docker commands, we can only run and manage a single container at a time, but there can be…

  • Day 16 of #90DaysOfDevOps Challenge

    Day 16 of #90DaysOfDevOps Challenge

    ?Docker: Docker is a containerization tool that helps us create a lightweight container with all the required packages…

  • Day15 of #90DaysOfDevOps Challenge

    Day15 of #90DaysOfDevOps Challenge

    ?Python Libraries: The collection of modules used in Python while writing different programs is known as libraries…

社区洞察

其他会员也浏览了