Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to install and use Docker on Ubuntu 20.04?

Introduction

Docker is a container platform that has revolutionised the way developers build, test and deploy applications. This manual will explain how to install and use Docker on Ubuntu 20.04, allowing developers to quickly and easily create applications in any environment.

Prerequisites

Before getting started with the Docker installation, you need to make sure that the following prerequisites are met:

  • A machine with Ubuntu 20.04 installed: Docker is compatible with Ubuntu 20.04, so you need to have a machine with this operating system installed.

  • Access to a user account with administrator permissions: To install Docker, administrator permissions are required.

  • Internet connection: To download and install Docker, a stable and fast Internet connection is required. In addition, Docker images may need to be downloaded from the Internet to create containers.

Installing Docker on Ubuntu 20.04

To install Docker on Ubuntu 20.04, the following steps are required:

1. Upgrade the system

Before installing any package, it is recommended to upgrade the system. To do this, open a terminal and run the following command:

sudo apt update && sudo apt upgrade

2. Install Docker

To install Docker, run the following command in the terminal:

sudo apt install docker.io

info This command will download and install Docker on the system.

3. Verify the installation

Once the installation is complete, you can verify that Docker has been successfully installed by running the following command:

docker --version

info This command should display the version of Docker installed on the system.

4. Add user to Docker group

To avoid running Docker commands with administrator permissions, you can add the current user to the Docker group. To do this, run the following command:

sudo usermod -aG docker $USER

info This command will add the current user to the Docker group.

5. Reboot the system

For the changes to take effect, you need to reboot the system. To do this, run the following command:

sudo reboot

info Once the system has rebooted, Docker is ready to be used.

It is important to note that if you are using a firewall on your system, you need to open port 2375 to allow Docker to communicate with the outside.

Using Docker

Once Docker is installed on Ubuntu 20.04, you can start using it to create and run containers. Here are some basic commands for working with Docker:

Download an image

Before creating a container, you need to download an image. Images are templates that are used to create containers. To download an image, the following command must be executed:

docker pull nombre_de_la_imagen

For example, to download the Ubuntu image, run the following command:

docker pull ubuntu

Create a container

Once you have downloaded the image, you can create a container from it. To create a container, run the following command:

docker run -it nombre_de_la_imagen

The -it parameter indicates that you want to run the container in interactive mode. For example, to create an archive from the Ubuntu image, run the following command:

docker run -it ubuntu

Exiting a container

To exit a container, the following command must be executed:

exit

List the running containers

To list the running containers, run the following command:

docker ps

List all containers

To list all containers, including non-running containers, run the following command:

docker ps -a

Delete a container

To delete a container, the following command must be executed:

docker rm nombre_del_contenedor

For example, to delete a container named my_container, you would run the following command:

docker rm my_container

Executing commands in a container

To execute commands in a running container, the following command must be executed:

docker exec -it nombre_del_contenedor comando

For example, to execute the ls command on a container named my_container, the following command must be executed:

docker exec -it my_container ls

success With these basic commands, you can start working with Docker and take advantage of all its benefits to create, test and deploy applications quickly and easily.

Conclusion

Docker is an essential tool for any developer who wants to quickly and easily build, test, and deploy applications in any environment. With Docker, developers can create containers that contain all the dependencies and configurations necessary for an application to run consistently, saving time and reducing configuration errors.