Docker is a powerful platform that enables you to develop, deploy, and run applications inside lightweight, portable containers. Containers allow you to package up an application with all of its dependencies into a standardised unit for software development, ensuring that it works seamlessly in any environment. This guide will walk you through the process of installing Docker on an Ubuntu system, breaking down each step to ensure that even those new to Docker or Ubuntu can follow along.
Prerequisites
Before you begin, you need to have:
A system running Ubuntu (we recommend using the latest LTS version for better stability).
A user account with sudo privileges, allowing you to execute commands with administrative rights.
Steps to install Docker on Ubuntu
Step 1: Update Your System
Start by updating your package lists to ensure you have access to the latest versions of the software. Open your terminal and run the following command:
sudo apt update
Optionally, you can also upgrade your installed packages to their latest versions with:
sudo apt upgrade -y
Step 2: Install Required Dependencies
Next, install a few necessary packages that allow apt to use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Step 3: Add Docker’s Official GPG Key
Docker’s official GPG (GNU Privacy Guard) key is required to verify the authenticity of the Docker packages. You can add it using the curl command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: Add Docker Repository to Ubuntu
To ensure you can install and update Docker from the official repository, add it to your system:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
This command adds the Docker repository and specifies your Ubuntu version to make sure you get access to compatible software versions.
Step 5: Install Docker Engine
With the Docker repository added, update your package lists again:
sudo apt update
Now, you’re ready to install the Docker Engine. Run:
sudo apt install docker-ce docker-ce-cli containerd.io -y
This command installs Docker Engine, the Docker CLI client, and containerd, a container runtime.
Step 6: Verify Docker Installation
To ensure Docker was installed successfully and is running, execute:
sudo systemctl status docker
If everything is set up correctly, you should see an output indicating that the Docker service is active and running.
Step 7: Running Docker as a Non-root User
By default, running Docker commands requires sudo. To avoid this and run Docker commands as your non-root user, you can add your user to the Docker group:
sudo usermod -aG docker ${USER}
For this change to take effect, you'll need to log out and log back in, or you can run the following command:
su - ${USER}
Verify that you can run Docker commands without sudo:
docker run hello-world
This command downloads a test image and runs it in a container. If successful, you’ll receive a greeting message from Docker!
Step 8: Updating Docker
To update Docker in the future, simply run the standard apt commands:
sudo apt update
sudo apt upgrade docker-ce docker-ce-cli containerd.io
Conclusion
Once you follow all the steps mentioned above, you have successfully installed Docker on Ubuntu. You’re now ready to explore the world of containerization, create Docker images, and run containers. Docker simplifies the deployment of applications, ensuring consistency across environments, and with your Ubuntu system, you have a robust platform for all your development needs.
Remember, Docker is a vast topic with much to explore, so don't hesitate to dive into the official Docker documentation and experiment with different Docker commands and features to broaden your understanding and skills.
0 comments:
Post a Comment