Click here to Skip to main content
15,886,810 members
Articles / Containers / Docker
Tip/Trick

A Fresh Start: Setting Up Ubuntu with Docker

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 May 2023CPOL2 min read 5.8K  
Learn how to set up a fresh Ubuntu installation with Docker, enabling you to leverage the power of containerization for efficient development and deployment.
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:

Shell
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:

  1. Install the required packages to allow apt to use a repository over HTTPS:
    Shell
    sudo apt install apt-transport-https ca-certificates curl software-properties-common 
  2. Import the Docker GPG key to ensure the authenticity of the software package:
    Shell
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 
         sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
  3. Add the Docker repository:
    Shell
    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
  4. Update the apt package index and install Docker:
    Shell
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io
  5. Verify that Docker is installed correctly by running a simple "hello-world" container:
    Shell
    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:

  1. Create the "docker" group (if it doesn't already exist):
    Shell
    sudo groupadd docker
  2. Add your user to the "docker" group:
    Shell
    sudo usermod -aG docker $USER
  3. 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:

  1. Check the Docker version:
    Shell
    docker --version
  2. Pull and run a popular Docker image, such as "nginx":
    Shell
    docker run -d -p 80:80 nginx
  3. 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
A seasoned technical architect with over 14 years of experience in developing and implementing software solutions for clients across various industries. Proficient in developing and maintaining software architectures, providing technical direction to development teams, and ensuring the timely delivery of high-quality software solutions. Excellent communication and interpersonal skills, with a proven ability to collaborate effectively with both technical and non-technical stakeholders.

Comments and Discussions

 
-- There are no messages in this forum --