On most other Linux distributions, including Ubuntu 23.04, Docker can be downloaded and installed. Similar to how you would use your distro’s package management to get an app, you may use Docker to install software packages once it has been installed.
Docker’s well-known technology allows programmers to create, distribute, and operate applications within containers. These containers offer a remote environment for running applications and are compact and portable. The operating systems Linux, Windows, and macOS all support, Docker. For a seamless software deployment experience, learn how to keep a secure environment and up-to-date by updating Docker Image and Container.
Option 1: How to Install Docker on Ubuntu 22.04, 23.04, 20.04?
Here you will get to know about how to set up Docker on Ubuntu 18.04, 20.04, 22.04, or 23.04. The installation procedure is simple, and the procedures listed below are simple. Make sure you have sudo privileges on your Ubuntu machine before we start. You’ll be able to install Docker and issue administrative commands.
Step 1: First of all, Update your Ubuntu System.
The first step is to refresh the repositories. To do so, run the command:
$ sudo apt update
The above command is used to update the package database on your Ubuntu system. It helps to make sure that the system contains the latest information about available packages or their support.
Step 2: Before Installing Docker, Install Prerequisite Packages
A few required packages that enable apt-to-use packages through HTTPS must then be installed. Use the following command to install these packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
The packages required for apt to use an HTTPS repository are installed by this command. It consists of the apt-transport-https package, which enables apt to access repositories using the HTTPS protocol. The ca-certificates package provides SSL/TLS certificates for validating HTTPS connections. The GnuPG-agent and software-properties-common packages are also installed. The curl command-line tool enables data transfer using several protocols.
Step 3: Add Docker’s Official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
The official GPG key for Docker is retrieved and added to the system with this command. Prior to installation, the integrity of Docker packages is checked using the key.
Step 4: Time to Add the Docker Repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
The Docker repository is added to your system’s list of software sources with this command. The unclear argument indicates the Ubuntu distribution codename. The repository contains the Docker packages for Ubuntu 22.04. You would use focused instead of hirsute in this command if you are running Ubuntu 20.04.
Step 5: Here you can Specify the Installation Source
Run the apt-cache command to verify the source for the Docker installation. It is the Docker repository and not the Ubuntu repository. The apt-cache command searches the apt package manager’s package cache for the early added Docker packages.
apt-cache policy docker-ce
Step 6: Finally Install Docker with the Command Below
sudo apt install docker-ce -y
Step 7: Here you can check the Docker Status
Check if Docker is installed, the daemon starts, and the process is enabled to start on startup. Run the following command:
sudo systemctl status docker
Option 2: Installing Docker from the Default Repositories
Step 1: Before Installing, Update the Repository
sudo apt update
Before you install the docker you need to update the repository with the above command and then the process of installation.
Step 2: Now you can Install Docker
sudo apt install docker.io -y
With this command, you can install the docker from the default repositories.
Step 3: After the Installation of Docker you should Install Dependencies
sudo snap install docker
Once the installation is done of docker you should install dependencies with the command given above.
Step 4: Check the Installation in Final Step
sudo systemctl status docker
At the final stage, you need to check the installation by the command which is shown above for you to make the confirmation. Alternatively, check the program version by running:
docker --version
How to Use Docker on Ubuntu
Run the docker command in the terminal to access all Docker information, including syntax, options, and commands:
docker
Downloading Docker images, building containers, and controlling Docker volumes are the first steps in utilizing Docker.
Working With Docker Images
The foundation for creating Docker containers is Docker images. The images can be found on Docker Hub, a repository for Docker files. All users can host their images on Docker Hub thanks to the repository, which produces a large selection of images, including Linux distributions and apps. The sections below demonstrate various approaches to using Docker images.
Lookup Docker Images
Use the docker search command to look for available images on Docker Hub. As for the syntax:
sudo docker search [keyword]
Enter the search term you want to use for [keyword]. Run: for instance, to display all Ubuntu pictures.
sudo docker search ubuntu
The result is a list of all photos that contain the keyword “Ubuntu.” If the [OK] parameter appears in the OFFICIAL column, the official project developer uploaded the image.
Retrieve a Docker Image
Choose the image you want, then use the pull option to download it. As for the syntax,
sudo docker pull [image-name]
Run these commands to download the official Ubuntu image, for instance:
sudo docker pull ubuntu
Use the image to spin up a container once it has been downloaded. Instead, when attempting to create a container from an image that hasn’t been downloaded, Docker downloads the image first before proceeding to build the container.
Browse Downloaded Images
Run the command to see which images you have downloaded.
sudo docker images
A list of all the downloaded images on your computer is produced by the command. It is an Ubuntu and MySQL Docker image in our situation.
Employing Docker Containers
An isolated virtual environment called a Docker container is produced from a Docker image. Use an image you’ve already downloaded or include its name in the docker run command to have the image downloaded and a container created automatically.
Use the hello-world image, for instance, to start up a container and download a test picture. Run the command line:
sudo docker run hello-world
The command tells Docker to start a container and get the image from Docker Hub. After the container is created, a “Hello from Docker” greeting and an explanation of how it functions are displayed before Docker shuts it down.
Activate a Docker Container
Running a Docker container makes use of the run subcommand, much like in the test container produced in the preceding section. The following is the syntax for building a new Docker container:
sudo docker run [image-name]
Indicate the name of the picture to be used as the container’s foundation for [image-name]. Docker gives each new container it creates a distinct name. As an alternative, you can start a fresh container and give it a name by using the –name switch:
sudo docker run --name [container-name] [image-name]
Run the following command, for instance, to build a container using the Ubuntu image we previously downloaded:
sudo docker run ubuntu
Although it is in non-interactive mode, the command generates a container from the picture that is supplied. Use the -i and -t switches to get interactive shell access to the container. For instance:
sudo docker run -it ubuntu
The terminal updates itself to state that it is functioning inside the container and references the container ID to do so. To remove, start, or stop the container, use its ID.
Pass any command to interact with the system after starting the container in interactive mode. Additionally, since root has access, sudo is not required. Any modifications made inside the container only affect that particular container. Run the exit command from the prompt to leave the container.
Check out Docker Containers
A Docker container that is currently running is said to be active. A container can be started, stopped, or removed using the unique ID and name that are output while listing containers.
Run: to only see active Docker containers.
sudo docker ps
An active container list is produced by the command. The containers have all been shut down, however, they are still present in the system if there are no containers on the list.
Add the -a flag to list all containers, even dormant ones:
sudo docker ps -a
sudo docker ps -l
Open a New Docker Container
Use the docker start command to restart a halted container. As for the syntax:
sudo docker start [container-ID | container-name]
Give the container name or the container ID. The name given to the container by Docker when it is created is distinctive. List all of the containers to obtain the ID and name. For instance, the Ubuntu container we previously established is started by the following command:
sudo docker start 5f9478691970
Terminate a Docker Container
Use the docker stop command to terminate a running Docker container. As for the syntax:
sudo docker stop [container-ID | container-name]
Run: for example, to terminate the active Ubuntu container.
sudo docker stop 5f9478691970
Uninstall a Docker Container
Use the docker rm command to delete a needless Docker container. As for the syntax:
sudo docker rm [container-ID | container-name]
For instance, the container we previously built for the hello-world test is removed by the following command:
sudo docker rm silly_hamilton
Final Words on Installing Docker on Ubuntu Linux
Install the necessary dependencies before updating the system repositories. With the “$ sudo apt update” command to install Docker on Ubuntu 23.04. After that, import the Docker GPG key, and then add the repository to the system sources. To efficiently manage your Docker environment, explore how to Remove/Delete Docker Images, Containers, and Volumes to keep your system clean and optimized.
The next step is to install Docker with the command “$ sudo apt install docker-ce”. This article covered how to set up Docker on Ubuntu 23.04. Hope you don’t get confused about the install docker ubuntu or you can say Installation of Docker On Ubuntu 18.04 |20.04 | 22.04 | 23.04
Frequently Asked Questions (FAQ)
1. What is Docker and why should I use it?
Docker is a platform for developing, shipping, and running applications in isolated containers. Docker is installed on each server and provides simple commands that you can use to build, start, or stop containers.
2. How can I Verify that Docker is installed correctly?
Running the following command you can check the docker’s status:
sudo systemctl status docker