What is Docker?

Sahan Jayasuriya
3 min readJan 23, 2023

Docker is a powerful platform for building, shipping, and running distributed applications. It is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Docker is used in a variety of ways, but it is most commonly used for creating and managing containers for applications. Developers can use Docker to package an application and its dependencies into a container, which can then be run on any machine that has the Docker engine installed. This allows for consistency in the environment across different stages of development, testing, and production. Docker can also be used to create and manage containers for databases, message queues, and other services.

Docker has many advantages over traditional virtualization methods. One of the main advantages is that Docker containers are lightweight and fast to start up. They use fewer resources than classic virtual machines, making them more efficient. Additionally, Docker allows for easy scaling of applications by adding or removing containers as needed. This allows for greater flexibility in managing and deploying applications. Furthermore, Docker can easily share and distribute containers, which helps speed up the development process.

Docker, however, also has some disadvantages. One of the main disadvantages is that it can be difficult to manage and maintain a large number of containers. This can be particularly challenging for large and complex applications. Additionally, Docker does not provide as much isolation as traditional virtual machines, which can be a security concern. Additionally, Docker requires a certain level of expertise to configure and manage, which can be a barrier to entry for some users.

The following is a simple example of how to create and run a Docker container for a web application.

First, we need to have Docker installed on our machine, which can be done by following the steps here.

Then, we will create a file named "Dockerfile,” which will be used to define the container. In this example, the Dockerfile will use the official Node.js image and copy our application code into the container.

# Use an official Node.js runtime as the base image
FROM node:10
# Set the working directory
WORKDIR /usr/src/app
# Copy the application code into the container
COPY . .
# Install the application dependencies
RUN npm install
# Expose the port the application will run on
EXPOSE 3000
# Start the application
CMD ["npm", "start"]

We can then build the container using the following command:

docker build -t my-app .

After the container is built, we can then run it using the following command:

docker run -p 3000:3000 my-app

This will start the application on port 3000 inside the container and map it to port 3000 on the host machine.

Docker is a powerful platform for building, shipping, and running distributed applications. It offers many advantages over traditional virtualization methods, such as its lightweight and fast nature, easy scaling, and flexibility in managing and deploying applications. However, it also has some disadvantages, such as managing and maintaining many containers, raising security concerns, and creating a barrier to entry for some users. With a proper understanding and usage of Docker, it can greatly simplify the process of developing, testing, and deploying applications.

--

--

Sahan Jayasuriya

A simple and humble person who enjoys mingling with nature. Career is developing software, but life is full of laughter and adventure.