Docker has become an essential tool in the world of system development and administration, allowing the creation, distribution and execution of applications in isolated and consistent environments. In this comprehensive guide, we'll explore everything from the basics of Docker to practical examples of different use cases, including content from Docker Hub.
Introduction to Docker
Docker is a lightweight virtualization platform that allows you to package and distribute applications along with all their dependencies in containers. A container is a unit of software that includes everything needed to run an application, including code, runtime, libraries, and configurations
Advantages of using Docker
- Portability: Containers can run on any machine that has Docker installed.
- Isolation: Each container operates in an isolated environment, avoiding conflicts between applications.
- Scalability: Containers can be easily replicated to handle variable workloads.
- Consistency: Ensures that the application works the same way in different environments.
Key concepts: images and containers.
- Image: Template that contains a file system and settings needed to run an application.
- Container: Running instance of an image. It's an isolated environment.
Docker installation.
To install Docker, it depends on the operating system, it is available for Linux with any distribution such as Ubuntu, CentOS, Kali, etc., also available for Windows and MacOS. To install it, just follow the steps depending on the operating system you have in this link: https://docs.docker.com/engine/install/
Docker Basic Commands
Docker Run
The 'docker run' command is used to run a container from an image. For example:
This command runs a container based on the “nginx” image in the background and maps port 8080 of the container to port 80 of the host.
💡 Note: The detach '-d' flag is usually used to be able to continue using our terminal, since if it's not used, it's time to stop the container to continue using the command line.
Docker ps
Shows a list of running containers.
Docker ps -a
Shows the list of containers that are running and stopped over time.
Docker images
Lists the images available in the system.
Docker build
Build an image from a Dockerfile in the current directory.
Docker stop and Docker Start
Stops and starts a running container.
Creating and Managing Images
A Dockerfile is a text file that defines how an image will be constructed. Dockerfile example for a Node.js application
Here we can see an example showing a series of instructions that our DockerFile will have
- FROM: provides us with a base image. In this case we took the 18.17-alpine image, which is much lighter than an 18.17 node
- WORKDIR: this is where you will host our application in the container
- COPY: add the files from our local directory, all the dependencies so that you don't have any errors when doing the build
- RUN: create the application with node:18.17-alpine
- EXPOSE: this is where our application will be displayed, in this case on port 3000
- CMD: Specify which command we want to execute in the container
💡 Note: there is another instruction that is the ENTRYPOINT, which has been the entry to execute in the container as an example it would look like this
Docker networks
Types of Networks in Docker
- Bridge: internal private network for containers on the same host.
- Host: Share the host's network with the container
- Overlay: Multi-host network for communication between containers on different hosts.
Create and Manage Networks
Connecting Containers to Networks
Data Persistence
Assembling Volumes in Containers
It allows data to persist even after stopping or deleting a container.
Data in the Container vs Data in Volume
The data in the container is volatile and is lost when the container is deleted. The data in a volume persists
Copying data to/from Containers
Practical Use Cases
Deploying a Web Application with Nginx
Container Databases: MySQL and MongoDB
Isolated Development Environments
Create consistent development environments for different projects
Container Orchestration with Kubernetes
Kubernetes is a powerful tool for orchestrating and managing containers in a production environment
Exploring Docker Hub
Docker Hub is a public repository for container images, where individuals and companies can publish solution images.
Steps to Upload an Image to Docker-Hub
The first thing you need to have to upload an image to Docker-Hub is an account,
- Create your Docker Hub account:
If you don't have your Docker Hub account yet, go to https://hub.docker.com/ and sign up
- Install Docker on your local machine:
To install Docker on your systems, download and install it from the official website of docker https://www.docker.com/get-started/
- Sign in to Docker Hub from the command line
Open a terminal and use the following command to log in to Docker Hub with your username and password
You'll be asked to enter your Docker Hub username and password
- Label your image that you are going to upload
Make sure that the image you want to upload has an appropriate label. You can label the image using the following command
Example:
- Upload the image to Docker Hub
Use the following command to upload your tagged image to Docker Hub:
Example
- Verify the image in Docker Hub
After the image is pushed and you see that it has been successfully completed, you can review the repository in Docker Hub, in the section repositories to make sure that the image is available

💡 Note: As you can see, I have in my Docker Hub a React repository with different versions that I have done in the code, and just by doing a pull to your place they can contribute to the code, GitHub style with the docker pull robpalacios1/react-docker command: <Tag>
Where Tag can be the versions I have from 1.0.0 to the last one that is being the latest
Conclusion
Docker is a technology that has evolved the way we develop, deploy and manage applications. From creating images to managing networks and volumes, Docker provides the tools needed to build consistent and efficient environments.
Ready to take your applications to the next level with Docker?
At Kranio, we have experts in containerization and DevOps who will help you implement efficient solutions using Docker, optimizing your development processes and ensuring the scalability of your applications. Contact us and discover how we can promote the digital transformation of your company.