Docker Quick Guide: Essential Commands and Key Concepts for Developers

👉 Who Is It For

This guide is designed for developers and system administrators who are already familiar with Docker and need a quick reference on essential commands. It is a memory aid to speed up daily work with containers.

🌊 Introduction to Docker

Docker is a container platform that allows you to run applications in an isolated and portable way. With Docker, developers can package software with all its dependencies into lightweight and efficient images, ensuring that they run consistently in any environment.

🔢 Key Docker Components

1. Images

Docker images are read-only templates that contain the operating system, libraries, and the code needed to run an application.

2. Containers

Containers are running instances of a Docker image. They are ephemeral, meaning that any changes made within the container are lost when stopped, unless data persistence is used.

3. Registries

The logs store Docker images and allow them to be shared with other users. Docker Hub is the most used public registry.

4. Volumes (Volumes)

Volumes allow data persistence in Docker, separating files from containers to prevent loss of information.

5. Networks

Docker networks facilitate communication between containers within the same work environment.

🔍 Key Differences in Docker

Dockerfile vs. Docker Compose

  • Dockerfile: Defines the configuration and environment of an individual container.
  • Docker Compose: It allows you to orchestrate multiple containers defined in a single YAML file.

COPY vs. ADD in Dockerfile

  • COPY: Copy files from the host system to the container.
  • ADD: It does the same thing as COPY, but it also allows you to download files from URLs and decompress compressed files.

Example of use in Dockerfile:

🌐 Ports in Docker

Docker allows you to map container ports to host system ports. Examples:

Common Docker ports include:

  • 80, 443: For web servers such as Nginx or Apache.
  • 3306: For MySQL databases.
  • 5432: For PostgreSQL.
  • 6379: For Redis.

🌐 Basic Commands in Docker

1. Run and manage containers

2. Build and manage images

3. Managing containers

4. Volumes for data persistence

5. Docker networks

🚀 Docker Compose

Docker Compose allows you to define and run Docker applications with multiple containers using a file docker-compose.yml.

Example of docker-compose.yml for an application with Nginx and PostgreSQL:

To execute:

📌 Base Template for a Docker Project

Example of a Dockerfile basic for starting an environment with Node.js:

🌟 Best Practices in Docker

  • Avoid using FROM node:latest, since it could cause inconsistencies with new versions.
  • Do not copy files directly from outdated repositories.
  • Version images using tags (Tags) to avoid compatibility issues.
  • In docker-compose.yml, it is no longer necessary to specify the version, since Docker Compose automatically detects the appropriate configuration.
  • Use multiple FROM in Dockerfile if different compilation and execution environments are required (Multistage builds).
  • Do not run processes such as Root inside the container, it's better to create a specific user.
  • Minimize the size of images by using lighter base images such as Alpine.
  • Eliminate unnecessary containers, volumes, and networks with Docker system prune to free up space.

🏆 Conclusion

Docker is a fundamental tool for modern development, allowing the creation of consistent and replicable environments. Mastering its commands and best practices ensures better management of containerized applications.

Ready to master Docker and optimize your development processes?

At Kranio, we have experts in containerization and DevOps who will help you implement best practices with Docker in your projects. Contact us and discover how we can improve the efficiency and scalability of your applications.

Karla Cabañas

March 14, 2025