This guide will demonstrate how to install Docker CE on Linux Mint 21 or 20, a process essential for leveraging Docker’s robust capabilities on your Linux system.
Docker CE stands as a powerful platform for developing, shipping and running applications efficiently. Known for its ease of use and versatility, Docker CE facilitates containerization, allowing you to encapsulate applications in containers, thereby improving portability and consistency across various environments.
Key Features of Docker CE:
- Container Management: Simplifies the creation, deployment, and scaling of applications.
- Portability: Ensures applications run consistently across different environments.
- Microservices Architecture: Ideal for building and managing microservices-based applications.
- Version Control for Containers: Tracks changes in containers, enhancing collaboration and development.
- Resource Efficiency: Offers higher efficiency than traditional virtual machines, optimizing system resources.
Transitioning from the conceptual to the practical, the installation of Docker CE on Linux Mint involves a series of straightforward steps. This installation not only equips your system with Docker’s containerization capabilities but also sets the stage for a more streamlined and efficient development workflow. Let’s delve into the installation process, which will unlock the full potential of Docker CE on your Linux Mint environment.
Docker CE Pre-Installation Steps on Linux Mint 21 or 20
Skip this section if you do not have Docker from Linux Mint’s repository installed.
Step 1: Remove Previous Docker Instances on Linux Mint
Before installing Docker CE on Linux Mint, it’s crucial to clear any existing Docker versions. This step is necessary to avoid conflicts with the new installation. If Docker has never been installed on your system, you can skip this step.
To remove any existing Docker installations, execute:
sudo apt remove docker docker-engine docker.io containerd runc
This command ensures that any previous versions of Docker and its associated components are removed from your system. If there are no Docker instances to remove, you’ll receive a message indicating so.
Keep in mind, uninstalling Docker doesn’t delete Docker images, containers, volumes, or networks, which are stored in /var/lib/docker/
. To completely remove all Docker data and start with a clean slate, use the following commands:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Executing these commands deletes all Docker-related data, prepping your system for a fresh Docker CE installation.
Step 2: Update Linux Mint Packages Before Docker Installation
After clearing old Docker versions, the next step is to update your Linux Mint system. This ensures that all your system packages are current, reducing the risk of conflicts and security vulnerabilities.
Run the following command to update your package lists and upgrade any outdated packages:
sudo apt update && sudo apt upgrade
The sudo apt update
command refreshes your package index, ensuring you have the latest information on available packages. Following this, sudo apt upgrade
updates all installed packages to their latest versions.
Import Docker CE APT Repository on Linux Mint 21 or 20
Step 1: Install Initial Packages For Docker CE on Linux Mint
To prepare for Docker CE installation, your Linux Mint system might require additional packages. These packages are critical for accessing and verifying Docker’s repository. To install them, execute:
sudo apt install ca-certificates curl gnupg lsb-release dirmngr software-properties-common apt-transport-https
This command uses the apt
package manager to install several tools. ca-certificates
helps with certificate verification, curl
is used for data transfer, gnupg
manages encryption keys, and other tools ensure a smooth process.
Step 2: Add Docker CE GPG Key on Linux Mint
The next step is to import the Docker GPG key, which is vital for ensuring the integrity of Docker packages. The GPG key acts as a digital signature, confirming the authenticity of downloaded content.
To download and add the GPG key, use these commands:
wget -q https://download.docker.com/linux/ubuntu/gpg -O- | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
Here, curl
fetches the GPG key from Docker’s repository. The gpg --dearmor
command then processes the key into a binary format required by the apt
package manager.
Step 3: Add Docker CE APT Repository on Linux Mint
With the GPG key added, the next step is to add the Docker repository to your Linux Mint system. This repository contains the Docker packages needed for installation.
Execute the following command to add the Docker repository:
Ensure to import the correct Docker Community Edition APT repository for your version of Linux Mint.
Docker CE APT Repository For Linux Mint 21
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list
Docker CE APT Repository For Linux Mint 20
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list
These command constructs the repository entry, specifying your system’s architecture and linking to the GPG key for package verification. It adds the repository to your system’s software sources, enabling you to install Docker CE from a trusted source.
Install Docker on Linux Mint 21 or 20
Step 1: Update Linux Mint APT Cache After Docker CE Repository Import
After adding the Docker repository, it’s essential to update your system’s repository information. This step ensures your system recognizes the newly added Docker repository.
To update the repository, run:
sudo apt update
This command refreshes the package lists on your system, incorporating the latest versions of packages and their dependencies. It’s a critical step for maintaining a current and secure system.
Step 2: Install Docker on Linux Mint 21 or 20 via APT Command
With your repository information up to date, you’re ready to install Docker. The following command installs Docker along with several essential plugins:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Here, docker-ce
is the Docker Community Edition, docker-ce-cli
is Docker’s command-line interface, containerd.io
provides the container runtime, and the docker-buildx-plugin
and docker-compose-plugin
are valuable tools for building images and orchestrating multi-container Docker applications.
Step 3: Verify Docker CE Installation on Linux Mint
Once Docker is installed, it’s crucial to verify the installation. Run a test Docker image to confirm Docker is operational:
sudo docker run hello-world
This command fetches the hello-world
image from Docker’s repository, creates a container, and runs it. The output should display a welcome message, indicating that Docker is correctly installed and functional on your Linux Mint system.
Step 4: Running Docker as a Non-Root User on Linux Mint
For enhanced security, configure Docker to run under a non-root user. This mitigates risks associated with root-level access. Detailed instructions for this configuration will follow in a subsequent section.
Docker Troubleshooting Tip
If issues arise while working with Docker, a system reboot can often resolve path generation and other common problems.
To restart your Linux Mint system, use:
reboot
A reboot can help clear up transient issues and ensure your Docker environment is functioning optimally.
Managing Docker via Systemd on Linux Mint 21 or 20
Starting the Docker Service on Linux Mint via systemd
To use Docker, the Docker service must be active on your Linux Mint system. Start the service using systemd with this command:
sudo systemctl start docker.service
Executing this command initiates the Docker service and configures it for automatic launch at system boot, ensuring Docker is ready after each startup.
Stopping the Docker Service on Linux Mint via systemd
There may be scenarios where stopping the Docker service is necessary. Systemd allows you to do this easily:
sudo systemctl stop docker.service
This command stops the Docker service, preventing it from starting automatically on the next boot.
Restarting the Docker Service on Linux Mint via systemd
For troubleshooting or applying new configurations, restarting the Docker service is often required. Use this systemd command:
sudo systemctl restart docker.service
This restarts the Docker service, effectively reapplying the latest settings and changes.
Checking Docker Service Status on Linux Mint via systemd
To view the current status of the Docker service, whether running, stopped, or inactive, use this command:
sudo systemctl status docker.service
This provides detailed information about the Docker service’s operational state.
Enabling Docker Service on Linux Mint System Boot via systemd
For Docker to start automatically at system boot, enable it using systemd:
sudo systemctl enable docker.service
This command configures Docker to automatically initiate at each system boot.
Disabling Docker Service on Linux Mint System Boot via systemd
To prevent Docker from automatically starting at system boot, systemd can be used to disable it:
sudo systemctl disable docker.service
This alters Docker’s settings, stopping it from auto-launching at boot.
Step 1: Run Docker as a Non-Root User
Running Docker as a non-root user is recommended to mitigate security risks and prevent accidental system alterations. Set up a dedicated user account for managing Docker:
sudo useradd -m dockeruser
sudo usermod -aG docker dockeruser
These commands create a new user dockeruser
and add this user to the Docker group, allowing the execution of Docker commands without root privileges.
To add your current user to the Docker group, substitute dockeruser
with your username.
For example, for a user joshua
:
sudo usermod -aG docker joshua
After adding the user to the Docker group, log out and log back in for the changes to take effect. Do not forget to reboot for the new changes to be activated:
sudo reboot
Verify the user’s Docker command permissions with:
docker ps
This command should list running Docker containers, confirming successful Docker setup under the non-root user.
Step 2: Modify Default Docker Logging Driver on Linux Mint
Docker defaults to JSON file format for logging events. However, you can change this to other formats or even configure Docker to forward logs to a remote logging system.
To change the logging driver, create a daemon.json
file in /etc/docker/
. Use a text editor like nano:
sudo nano /etc/docker/daemon.json
In the editor, input the following:
{
"log-driver": "syslog",
"log-opts": {
"syslog-address": "tcp://logs.example.com:514",
"syslog-facility": "daemon",
"tag": "{{.Name}}"
}
}
This configuration uses the syslog driver and forwards logs to a remote syslog server. Replace logs.example.com
with your syslog server’s address.
After updating the configuration, restart the Docker daemon to apply the new settings:
sudo systemctl restart docker.service
Remember, any changes to the daemon.json
file require restarting the Docker daemon for the modifications to take effect.
Docker Command Examples on Linux Mint 21 or 20
Fundamentals of Docker Commands on Linux Mint
Mastering Docker’s command line interface (CLI) is key to effectively managing containers, images, networks, and volumes. Here’s an overview of frequently used Docker commands:
- docker run: Starts a new container from an image.
- docker ps: Shows all active containers.
- docker images: Lists available local images.
- docker build: Builds a new image from a Dockerfile.
- docker stop: Stops a running container.
- docker rm: Removes a container.
- docker rmi: Deletes an image.
- docker network: Manages Docker networks.
- docker volume: Handles Docker volumes.
Each command offers options to tailor its functionality to specific requirements.
The docker run Command
Use docker run
to initiate a container from an image. For example, to start a container from the latest Ubuntu image with an interactive shell:
docker run -it ubuntu:latest /bin/bash
The docker ps Command
docker ps
lists all active containers, providing details like container ID, image used, and status:
docker ps
The docker images Command
docker images
shows all locally stored Docker images, displaying their ID, repository, and tag:
docker images
The docker build Command
docker build
constructs a new image from a Dockerfile. For example, to build an image named ‘customimage’ using a Dockerfile in the current directory:
docker build -t customimage:latest .
The docker stop Command
docker stop
gracefully shuts down a running container. Specify the container ID, for instance:
docker stop container123
The docker rm Command
Remove a Docker container with docker rm
, indicating the container ID:
docker rm container123
The docker rmi Command
To delete Docker images, use docker rmi
. Identify the image by its ID:
docker rmi image12345
The docker network Command
docker network
is used for network-related tasks like creating, listing, or removing networks. To create a network named ‘network1’:
docker network create network1
The docker volume Command
Manage Docker volumes with docker volume
. To create a volume named ‘volume1’:
docker volume create volume1
Navigating Docker Container Management on Linux Mint 21 or 20
Core Commands for Docker Container Management with Linux Mint
Mastering Docker’s command-line interface is key to effective container management. Key commands include:
docker ps
Lists all active containers, displaying their image, status, and ID.
docker ps
docker stop
Stops an active container. Append the container’s ID or name.
docker stop unique_container_id
docker rm
Removes a container, also using the container’s ID or name.
docker rm unique_container_id
Removing a container with docker rm
discards any unsaved changes. To preserve modifications, utilize the docker commit
command.
Retaining Container Changes using docker commit
Creating a new image with saved changes in a Docker container is achieved using docker commit
.
Starting a Container and Making Modifications
Start a new container from a base image and modify it:
docker run -it --name custom_container ubuntu:latest /bin/bash
Perform tasks like editing files or installing software within this container.
Saving Changes with docker commit
After making changes, use docker commit
to create a new image encapsulating these modifications:
docker commit custom_container mycustomimage:latest
This creates a new image mycustomimage
with the alterations made in custom_container
. Use this image for new containers with the updated setup.
Remember, docker commit
only saves filesystem changes, not modifications to networking and storage. For comprehensive changes, explore additional Docker commands like docker network
and docker volume
.
Conclusion
Alright, we’ve journeyed through the essentials of Docker on Linux Mint, from installing and configuring to managing containers like a pro. Remember, keeping Docker updated and running as a non-root user is key for security. Don’t forget to use docker commit
wisely to save those crucial changes. As you dive deeper, experiment and explore – Docker’s quite the toolbox! Stay curious, keep tweaking, and you’ll master the art of container management in no time.
Awesome guide, tried a few other guides but this worked, well done and thanks.