Skip to main content

Command Palette

Search for a command to run...

Day 17 Task: Docker Project for DevOps Engineers.

Published
3 min read
Day 17 Task: Docker Project for DevOps Engineers.

Docker file:

The Dockerfile uses DSL (Domain Specific Language) and contains instructions for generating a Docker image. Dockerfile will define the processes to quickly produce an image. While creating your application, you should create a Dockerfile in order since the Docker daemon runs all of the instructions from top to bottom.

Steps To Create a Dockerfile

  • Create a file named Dockerfile.

  • Add instructions in Dockerfile.

  • Build Dockerfile to create an image.

  • Run the image to create a container.

Important Dockerfile Keywords

  1. FROM:

    Represents the base image(OS), which is the command that is executed first before any other commands.

    FROM ubuntu:19.04

  2. COPY:

    The copy command is used to copy the file/folders to the image while building the image.

    COPY <Source> <Destination>

  3. ADD:

    While creating the image, we can download files from distant HTTP/HTTPS destinations using the ADD command.

    ADD <URL>

  4. RUN:

    Scripts and commands are run with the RUN instruction.

    RUN touch file

  5. CMD:

    The main purpose of the CMD command is to start the process inside the container and it can be overridden.

    CMD [command + args]

  6. ENTRYPOINT:

    When you start the Docker container, a command or script called ENTRYPOINT is executed. It can’t be overridden.

    ENTRYPOINT [command + args]

  7. ENV:

    This command sets the environment variable in the container.

  8. EXPOSE:

    This command informs Docker that the container listens on the specified network ports at runtime.

TASK:

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

  2. Build the image using the Dockerfile and 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 )

STEP 1:

create a directory/folder in EC2. install python3 and Django. migrate python3 manage.py and run the server.

NOTE : When you run the command python3 manage.py runserver, it'll throw an error on the timezone. All you have to do is go to the 'django-todo/todoApp/settings.py' and change the timezone from Kolkata to Dhaka.

And then use migrate command

STEP 2:

Install docker and create Dockerfile. build image from it and then run the container.

use docker build -t test . command where test is my image name to build an image from Dokcerfile.

Use the docker run command to create a container from the image.

Now add this port number to the security group of your instance. If you don't add the port number then you'll not be able to access the application.

Once you add the port number to inbound group then also you'll get the above error. To remove that error go to the 'django-'todo/todoApp/settings.py' and edit it by adding the public IP of your ec2 instance in the allowed host. Once you do it you'll be able to access the application.

Note: Later I changed port number 8001 to 8000 that's why you're seeing the 8000 port in the image. If you follow the above steps then use the 8001 port.

STEP 3:

Create an account on the docker hub and push your image.

Use the docker login command and give username and password to save login details of docker hub in ec2.

Note: to push your image to docker hub you'll have to change the name of the image in [docker_username]/[image_name] format by using the docker tage command.