Getting Started with Docker: A Beginner's Guide

Getting Started with Docker: A Beginner's Guide

ยท

2 min read

Hello friends,

Docker is an essential and must-have technology these days, but learning and implementing Docker can seem challenging. However, by the end of this blog, you'll find it much easier! ๐Ÿ˜Š

In this article, I will discuss the basic steps that must be included in every Docker file.

The 5 Essential Steps in Every Docker file

  • FROM

  • WORKDIR

  • COPY

  • RUN

  • CMD

Let's understand each step in detail

  1. FROM

Here, we fetch and load the base OS required for our application.

  1. WORKDIR

In this step, we create and define the working directory where we will place our actual code.

  1. COPY

Here, we copy the required source files to our working directory.

  1. RUN

In this step, we install the project dependencies.

  1. CMD

Here, we define the startup file and how we can run it.

Example: Dockerizing a Python Application

# Step 1: Specify the Base OS
FROM "ubuntu:20.04"

#Step 2: Define the Working Directory as "/app"
WORKDIR /app

#Step 3: Copy the Source Files to the Working Directory
# Two . .  means copy all files from source directory to destination directory
# The first dot represents the source (all files from the root directory of the source)
# The second dot represents the destination (put it in the root directory of the destination).
COPY . .

#Step 4: Install the Required Dependencies
# Since we are using Ubuntu as the base OS, we run the apt-get install command to install the Python 3 library.
RUN sudo apt-get install python3

#Step 5: Define the Startup File to Run
# Here, python3 is the entry point, and main.py is the startup file from which our code execution will start.
CMD ["python3", "main.py"]

This way, you can start working with the basics of a Dockerfile. In the next articles, we will dive into more advanced concepts.

Happy coding! ๐Ÿ’ปโœจ

ย