Docker and Docker-Compose on Ubuntu
In this tutorial, let’s learn how to install and set up Docker and Docker-Compose on Ubuntu
Docker
- It is an open platform for developing, shipping, and running applications
- In short, it provides the ability to package and run an application in a loosely isolated environment called a container
- Further, Containers are lightweight and contain everything needed to run the application
- As a result of this, they use fewer resources compared to Virtual Machines
Docker Compose
- It is a tool for defining and running multi-container Docker applications
- It requires a single configuration file for all services (in YAML)
- Due to this, the configuration is cached whenever possible. In other words, this speeds up further operations on containers
- When a service that has not changed is restarted, it re-uses the existing containers
Read more on Docker and Docker Compose here:
https://docs.docker.com/get-started/overview/
https://docs.docker.com/compose/
Steps to install Docker on Ubuntu
1. Update the apt repository and install the required package
# Update the apt repository
sudo apt-get update
# Install the required packages
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
2. Next, add Docker’s official GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3. Set up the stable repo according to the Operating System Architecture. Run the respective command based on OS Architecture
# For x86_64 / amd64
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
# For armhf
echo \
"deb [arch=armhf 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
# For arm64
echo \
"deb [arch=arm64 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 apt and install the latest version of Docker Engine
# Update the apt repository
sudo apt-get update
# Install Docker engine and required components
sudo apt-get install docker-ce docker-ce-cli containerd.io
5. Finally enable docker service to Start on boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
Setup Docker for non root user
# Create docker group (if not present)
sudo groupadd docker
# Add non root user to the docker group
sudo usermod -aG docker $USER
# Activate Changes
newgrp docker
# Reboot to apply all changes
sudo reboot now
# Test by running below command without sudo
docker run hello-world
Steps to install Docker Compose on Ubuntu
1. Install python3 and pip
sudo apt install python3 python3-pip
2. Once it is done, Install Docker Compose using pip
sudo pip install docker-compose
Congratulations!!! You have successfully installed Docker and Docker-Compose on your Ubuntu machine
Pingback:Portainer on Docker - Manage all your docker containers » EasyCode
Pingback:Watchtower on Docker - Automate Docker image updates » EasyCode
Pingback:Nginx Proxy Manager on Docker - Reverse Proxy » EasyCode
Pingback:PrivateBin - OpenSource PasteBin on Docker » EasyCode
Pingback:Filebrowser on Docker » EasyCode
Pingback:Navidrome - A Self-Hosted Music Server on Docker » EasyCode
Pingback:Gitea - A Self-Hosted Private Git Server on Docker » EasyCode
Pingback:Gitea - Setup SSH and Repository » EasyCode
Pingback:Code-Server - VS Code on Docker » EasyCode
Pingback:Basics of Linux - Part 1 (User, Group Management) » EasyCode
Pingback:Change Data Capture (CDC) with Debezium and Kafka » EasyCode