In this article, we explore the process of setting up a fresh Ubuntu installation with Docker, a powerful containerization platform. By combining Ubuntu's stability and user-friendliness with Docker's ability to package and distribute applications within containers, developers can create a versatile development and deployment environment. We guide readers through the steps of installing Ubuntu, updating the system, installing Docker, and managing it as a non-root user. By the end of this blog, readers will have a solid foundation for utilizing Ubuntu and Docker together, enabling them to streamline their development workflow and harness the benefits of containerization.
Introduction
Ubuntu is one of the most popular Linux distributions, renowned for its stability, versatility, and user-friendly interface. When combined with Docker, an open-source platform for containerization, Ubuntu becomes an incredibly powerful development and deployment environment. In this article, we will guide you through the process of setting up a fresh Ubuntu installation with Docker, enabling you to leverage the benefits of containerization for your projects.
Step 1: Installing Ubuntu
The first step is to install Ubuntu on your machine. You can download the latest Ubuntu ISO file from the official website (https://ubuntu.com/download). Once you have the ISO, create a bootable USB drive or use a virtual machine to install Ubuntu. Follow the installation wizard, select your preferences, and complete the installation process.
Step 2: Updating Ubuntu
After the installation, it's crucial to update Ubuntu to ensure you have the latest security patches and software updates. Open the Terminal and execute the following commands:
sudo apt update
sudo apt upgrade
Enter your password when prompted and allow the updates to install. This process might take some time, depending on your internet speed and the number of updates available.
Step 3: Installing Docker
Now that Ubuntu is up to date, we can proceed with installing Docker. Docker provides a convenient way to package, distribute, and run applications within containers, ensuring consistency across different environments. Open the Terminal and execute the following commands:
- Install the required packages to allow apt to use a repository over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
- Import the Docker GPG key to ensure the authenticity of the software package:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Add the Docker repository:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the
apt
package index and install Docker:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
- Verify that Docker is installed correctly by running a simple "
hello-world
" container:
sudo docker run hello-world
Step 4: Managing Docker as a Non-root User
By default, Docker requires root privileges to execute Docker commands. However, it is recommended to manage Docker as a non-root user for security reasons. To achieve this, you can add your user to the "docker
" group:
- Create the "
docker
" group (if it doesn't already exist):
sudo groupadd docker
- Add your user to the "
docker
" group:
sudo usermod -aG docker $USER
- Log out and log back in to apply the group changes.
After completing these steps, you should be able to use Docker without sudo by simply running Docker commands in the Terminal.
Step 5: Testing Docker Setup
To confirm that your Docker setup is working correctly, you can run a few additional tests:
- Check the Docker version:
docker --version
- Pull and run a popular Docker image, such as "
nginx
":
docker run -d -p 80:80 nginx
- Open your web browser and navigate to http://localhost. If everything is working correctly, you should see the default Nginx page.
Congratulations!!
History
- 11th May, 2023: Initial version