Guide to Installing Docker on Ubuntu 24.04 LTS



Introduction

Docker is a lightweight virtualization utility that enables the deployment of OS images and packages that help to run the required applications like PHP, Java, Python, Angular, GoLang, etc.

Prerequisites

  • Up and running ubuntu machine.
  • 1 core CPU and 2 GB memory for minimal requirements.
  • 10 GB disk space. (This will be the minimum requirement.


Step 1: Run System Update & Upgrade 

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo apt-get update && sudo apt-get upgrade -y



Step 2: Adding Docker Repository and GPG Key 

Execute the given command that is required to install Docker.

sudo apt install apt-transport-https ca-certificates curl software-properties-common -y


To adding the GPG key.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg


To add the repository.

echo "deb [arch=$(dpkg --print-architecture) 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


To update the ubuntu repository and more.

sudo apt-get update && sudo apt-cache policy docker-ce 


Step 3: Install Docker Community Edition

We are ready to install the Docker community edition package by executing the command.

sudo apt-get install docker-ce -y


Step 4: Verify Docker Service Status

This is the good practice to check the Docker service by executing the given command.

sudo systemctl status docker.service



Step 5: Docker Command Without Sudo

By default we need to use the sudo command to apply Docker CLI and their changes, but sometimes it creates problems. Avoid using sudo every time with the Docker command.

sudo usermod -aG docker ${USER}


To add the new membership group, log out and log in again to the server or type the following:

su - ${USER}



To verify and check added user in docker group.

groups



If you want to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

sudo usermod -aG docker ${USER}


Step 6: Docker System-Wide Info

We need to execute given command, To view system-wide information about Docker.

docker info



Step 7: Deploy Apache Docker Image 

We can test Docker functionality with an official Docker apache image, Use the given command for the same.

To pull the docker image.

docker pull httpd:latest


To create a directory for Apache web server's configuration and their web files.

mkdir -p ~/apache-docker/{htdocs,conf}


  • htdocs/: Directory for website files.
  • conf/: Directory for custom Apache configuration (optional).

To add some sample content to htdocs/:

echo "<h1>Welcome to Apache on Docker</h1>" > ~/apache-docker/htdocs/index.html



Step 8: Deploying Apache Docker Container  

Use the given command to deploy the apache container.

docker run -dit \
  --name apache-server \
  -p 80:80 \
  -v ~/apache-docker/htdocs:/usr/local/apache2/htdocs \
  httpd:latest


  • -dit: To run in detached mode.
  • --name apache-server: Assigning a container name.
  • -p 80:80: Mapping the host's port 80 with the container's port 80.
  • -v ~/apache-docker/htdocs:/usr/local/apache2/htdocs: Mounting the local htdocs directory to the container's document root.


Step 9: Verifying Deployment   

After executing the docker command line, we need to verify if the Apache Docker container is deployed or not. Use the given command for the same.

docker ps



Step 10: Testing Apache Default Webpage  

We are good to test the Apache default webpage with our custom message. For this, we need to visit the host IP and use the given web address for the same.

http://<IP-ADDRESS> or http://<localhost>


If everything is well configured and deployed, we should get an Apache test page like this.





Conclusion

We did install Docker on the Ubuntu 24.04 LTS machine using the command line utility to enable virtualization to deploy Docker images.



Aftab Ali

My expertise is in ethical hacking, penetration testing, network security, monitoring and more.

Post a Comment

Previous Post Next Post