DEV Community

Mukhtar Abdussalam
Mukhtar Abdussalam

Posted on

Docker for Beginners: Everything You Need to Know - Updated April 06, 2026

Diving into the world of Docker can feel a little like boarding a spaceship without your seatbelt fastened. The jargon, the commands, and the concepts might appear daunting at first, but fear not! By the end of this article, you'll have a sturdy grip on Docker basics, understand its significance in the modern development landscape, and even start running your first containers. So, buckle up, and let’s set sail into the world of Docker!

What is Docker and Why Use It?

Docker is a platform designed to help developers build, ship, and run applications inside containers. But wait, what exactly is a container? In simple terms, a container is a standardized unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Why Docker?

  • Consistent Environments: Containers ensure consistent development, staging, and production environments, reducing the lamentable "It works on my machine" syndrome.
  • Scalability: With Docker, scaling your application or service horizontally by deploying it across vast numbers of machines is straightforward and efficient.
  • Efficiency: Docker uses far fewer resources than virtual machines (VMs), as it shares a single kernel and requires less overhead, leading to faster start-up times.

Getting Started with Docker

Installing Docker

First thing's first—let's install Docker. Here's how you can do it on a few popular operating systems.

For Windows and macOS:
Head over to Docker's official website and download Docker Desktop. Follow the installation instructions provided there.

For Ubuntu:
Open your terminal and run the following commands:

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode

Running Your First Container

Once Docker is installed, verify the installation and start your first container by executing:

docker --version
docker run hello-world
Enter fullscreen mode Exit fullscreen mode

This command pulls the hello-world image from Docker Hub and runs it in a new Docker container, delivering a friendly message confirming the successful execution.

Basic Docker Commands You Should Know

Images and Containers

  • Images: These are read-only templates used to create containers. To pull an image, use:
  docker pull <image_name>
Enter fullscreen mode Exit fullscreen mode
  • Containers: These are instances of Docker images. To list all running containers:
  docker ps
Enter fullscreen mode Exit fullscreen mode

To list all containers (running and stopped):

  docker ps -a
Enter fullscreen mode Exit fullscreen mode

Building a Docker Image

Create a file named Dockerfile with the following content for a simple Node.js app:

# Use the official Node.js image
FROM node:14

# Create app directory
WORKDIR /usr/src/app

# Copy app files to the container
COPY . .

# Install app dependencies
RUN npm install

# Expose app port
EXPOSE 8080

# Command to run the app
CMD ["node", "app.js"]
Enter fullscreen mode Exit fullscreen mode

Build the Docker image using the following command:

docker build -t my-node-app .
Enter fullscreen mode Exit fullscreen mode

Running a Docker Container

Run a container from your image with:

docker run -p 8080:8080 my-node-app
Enter fullscreen mode Exit fullscreen mode

This command maps port 8080 of your local machine to the container's port 8080, allowing external access to your application.

Debugging Common Docker Issues

With Docker already established as a crucial part of modern development flows, running into issues can still occur. Here’s some quick advice:

  • Permissions Issues: If you encounter permission denied errors, ensure you're added to the Docker group with sudo usermod -aG docker $USER and restart your system or session.
  • Outdated Images: Regularly update your images using docker pull <image_name> to prevent encountering issues from deprecated versions.

Conclusion and Next Steps

Congratulations! You've just navigated through the essentials of Docker and even ran your first containerized app. Remember to experiment with more Docker features like Docker Compose and dive deeper into orchestrators such as Kubernetes.

Docker provides an opportunity-packed landscape that empowers developers to build once and deploy anywhere. Whether you're just adding Docker to your toolkit or exploring new capabilities, there's always more on the horizon. Share your experiences in the comments below and let me know what you'd like to explore next about Docker and containerization.

Feel free to follow for more insights into the world of software development, and don't hesitate to drop a comment if you have any questions or topics you want covered. Safe voyages in your Docker journey!

Top comments (0)