Docker is a fantastic open-source tool, much like a virtual machine, but designed to streamline application deployment. It excels at automating the deployment of applications along with everything they need to run, all within neat packages called Linux containers. These containers are super useful because they operate independently from your computer’s main operating system. This isolation makes deploying applications faster, troubleshooting easier, and maintenance a breeze, all while boosting security.
Think of a Docker container as a neatly packed instance of your application. It contains all the necessary bits and pieces – code, libraries, and settings – for the application to run smoothly. Containers are efficient with resources, easily moved around (portable), and completely self-contained, meaning they can run just about anywhere.
In this guide, we will walk you through installing Docker on Ubuntu 18.04. We’ll also explore the Docker CLI and show you how to work with Docker images.
Read: How to install Kubernetes on Ubuntu 18.04
If you install Docker directly from Ubuntu’s default software source, you might not get the very latest version. To ensure you’re running the newest features and updates, it’s best to install Docker from its official repository. To do this, we’ll first add Docker’s repository as a new source for software packages on your system. Then, we’ll add a GPG key. This key is like a digital signature that verifies the software you download is genuine and hasn’t been tampered with. Once these steps are done, we can proceed to install the Docker package itself.
Before installing any new software, it’s always a good practice to update your system’s package list. This makes sure you have the latest information about available software versions. Run the following command to update your package list:
1 sudo apt update
2 Next, to allow your system to download packages securely over the internet using HTTPS, you need to install a few tools. Run this command:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
3 Now, you need to add Docker’s GPG key to your system. This key confirms that the packages are coming from Docker and are safe to install. Use the following command to import the GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
Read: How to fix Docker error mkdir [folder]: read-only file system
4 Now, let’s tell your system where to find the Docker packages. We’ll add the Docker repository to your system’s list of software sources. This is done using the `add-apt-repository` command, which updates either the main list of sources (`/etc/apt/sources.list`) or adds a new file in the directory `/etc/apt/sources.list.d`. Run the command below to add the Docker repository:
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable”
With the Docker repository added, you are now ready to install Docker Community Edition (CE). This is the free and open-source version of Docker.
To install the latest version of Docker CE, simply run the following command:
sudo apt install docker-ce [Ubuntu install Docker]
Docker Linux install | Install Docker Ubuntu 18
Once this command finishes, Docker should be installed on your Ubuntu system. The Docker service (also known as the Docker daemon) should automatically start running, and it’s also set up to start automatically whenever your system boots up. To verify that Docker is up and running, use this command:
sudo systemctl status docker
Installing Docker also provides you with the `docker` command-line tool, often referred to as the Docker client. You’ll use this tool to interact with Docker.
Read: How to install and uninstall applications on Ubuntu – A Beginner’s guide
To use Docker, you’ll primarily interact with it through the `docker` command in your terminal. You’ll use different options, commands, and arguments to tell Docker what to do. The basic structure of a Docker command is:
docker (option) (command) [arguments]
To see a list of all available Docker subcommands, just type `docker` in your terminal and press Enter:
docker
If you need help with a specific subcommand, you can use the `–help` option. For example, to get help on the `run` subcommand, you would use:
docker [subcommand] –help
To get a general overview of your Docker installation and system information related to Docker, use the `info` command:
docker info
In Docker, everything starts with images. A Docker image is like a blueprint or a template. It contains a file system with all the necessary libraries, programs, and files, along with instructions on how to run an application. Containers are created from these images. Think of a container as a running instance of an image. Running containers is the core purpose of Docker.
Read: How to run and manage a Docker container on Linux Ubuntu/Debian
Let’s try a command to see how Docker fetches and runs images from Docker Hub, which is a public repository of Docker images. Run this command:
sudo docker run hello-world
The `run` command tells Docker to create and start a container based on the specified image.
Here’s what you might see as output when you run the command:
In the output shown, Docker first checked if the `hello-world` image was already on your local machine. Since it wasn’t found locally, Docker pulled (downloaded) it from Docker Hub, which is the default public registry for Docker images.
Once the image was downloaded, Docker created a container from it and ran the application inside the container. This application simply displays the “Hello from Docker!” message you see in the output. So, `hello-world` is the name of the image used to create and run this container.
Read: How to fix “Cannot Connect to the Docker Daemon” Error
Docker containers are built from Docker images. By default, these images are pulled from Docker Hub, a cloud-based registry managed by Docker. Docker Hub is a public repository where anyone can host and share their Docker images. You can find images for most popular Linux distributions and applications on Docker Hub.
For example, if you want to run CentOS, you can use the official CentOS image available on Docker Hub. To do this, run the following command:
sudo docker run -it centos /bin/bash
This command tells Docker to download the `centos` image from Docker Hub (if it’s not already present locally) and then start a container in interactive mode (`-it`).
Once the CentOS container starts running, `/bin/bash` is executed, which gives you a bash shell inside the CentOS container.
Read: How to speed up Linux
To see a list of Docker images that are currently downloaded and stored on your system, you can use the `docker images` command:
docker images
Here’s an example of what the output might look like:
Docker Ubuntu image
The output will show a table with information about your images, including these columns:
TAG − This is used to version or logically categorize images (e.g., `latest`, `18.04`).
Image ID − A unique identifier for each image.
Created − Shows how long ago the image was created.
Virtual Size − The size of the image.
To search for images on Docker Hub, for example, to find Ubuntu images, you can use the `docker search` command followed by your search term:
docker search ubuntu
This command will query Docker Hub and return a list of images that match your search term “ubuntu”. Here’s an example of the output:
In the “OFFICIAL” column, you might see `[OK]`. This indicates that the image is an official image, meaning it’s built and supported by the organization behind the software project (in this case, Ubuntu). To download an image to your local machine after you’ve found it using `search`, you can use the `pull` subcommand.
Read: How to clean up unused Docker containers, images and volumes
To download the official Ubuntu image, run the following command:
docker pull ubuntu
You’ll see output similar to this while the image is being downloaded:
Once the image is downloaded, you can then create and run containers from it using the `run` command.
As mentioned earlier, the `docker run` command is often used to download images from Docker Hub if they are not already available locally.
The basic syntax for downloading and running an image is:
Syntax
docker run image
Where `image` is the name of the image you want to use to run a container. When you run this command, Docker will first check if the image exists locally. If not, it will download the image from Docker Hub and then start a container based on that image. The output you see will depend on what the application inside the container does.
Here’s an example:
sudo docker run centos
If the `centos` image isn’t already on your system, Docker will download it, as we’ve seen before. After downloading (if needed), this command will run a container from the `centos` image.
If you now run the `docker images` command again:
sudo docker images
You should see the `centos` image in the list of downloaded images.
Docker images can be modified and used as a base to create new images. These new images can then be uploaded to Docker Hub or other Docker registries, allowing you to share your customized environments.
To delete a Docker image from your local system, you can use the `image rm` subcommand:
docker image rm [image_name]
For example, to remove the `centos` image, you would use: docker image rm centos
Docker offers a powerful set of tools for managing containers, including an API and an image format. It also provides access to Docker Hub, a central registry for sharing containers.
Using Docker brings several advantages to both system administrators and developers:
In this article, you’ve learned how to install Docker on Ubuntu 18.04, how to use the Docker CLI to interact with Docker, and how to work with Docker images. This is just an introduction to the vast capabilities of Docker. Stay tuned for more articles exploring Docker in greater depth!
The post How to install and setup Docker on Ubuntu 22.04 appeared first on net2.
When Ubuntu 22.04 users encounter network problems, they often face two main issues: one with…
Encountering the error “sudo systemd-resolved command not found error Ubuntu” indicates that your system cannot locate the systemd-resolved executable…
Optimizing your Ubuntu startup is essential for a seamless user experience and efficient system performance.…
Linux administrators and power users often need to run commands repeatedly. Whether you’re monitoring system…
If you are an Ubuntu 22.04 user, appreciating its user-friendly design and robust capabilities as…
Experiencing a sudden loss of audio on your Ubuntu 22.04 system can be incredibly frustrating.…