Skip to content

Techeons

Imagine | Explore | Innovate

Menu
  • Home
Menu

How to setup Docker and Docker Compose on Ubuntu

Posted on August 31, 2024

What is Docker?

Docker is a containerization platform that allows developers to package, ship, and run applications in containers. Containers are lightweight and portable, providing a consistent and reliable way to deploy applications across different environments.

Docker containers wrap an application’s code, dependencies, and configurations into a single package, making it easy to:

  • Develop and test applications locally
  • Deploy applications to production environments
  • Scale applications horizontally (add more containers)
  • Isolate applications from each other

What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to:

  • Define the services that make up your application in a single YAML file (docker-compose.yml)
  • Create and start all the services from your configuration with a single command (docker-compose up)
  • Manage the lifecycle of your application’s containers (start, stop, restart, etc.)

Docker Compose is ideal for development, testing, and staging environments, as well as small-scale production deployments.

Key benefits of Docker and Docker Compose:

  • Lightweight and portable: Containers are much lighter than virtual machines, making them easy to deploy and manage.
  • Consistent environments: Docker ensures consistent environments across development, testing, and production.
  • Easy scaling: Docker Compose makes it easy to scale your application horizontally.
  • Improved collaboration: Docker and Docker Compose make it easy to share and collaborate on applications.

Common use cases:

  • Web development (e.g., WordPress, Node.js, Ruby on Rails)
  • Microservices architecture
  • DevOps and CI/CD pipelines
  • Data science and machine learning
  • Legacy application modernization

1) Install Docker

# Remove old version
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# Install Docker
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

# Install Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Run Docker Hello World
sudo docker run hello-world

2) Install Docker Compose

curl -SL https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

OPTIONAL: To add / remove your user from docker group

# Add your user to the docker group
sudo usermod -aG docker $USER

# Remove user from docker group
sudo deluser $USER docker

Useful links:

  • https://docs.docker.com/engine/install/ubuntu/
  • https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user

Share on Social Media
x facebook pinterest linkedin tumblr reddit emailwhatsapptelegrammastodon

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Nginx: How to increase timeout for Nginx
  • Cheat Sheet: Essential Git Commands
  • Setting a default shell in Linux
  • Setting up Composer on Linux
  • Switch easily between Python versions on a Mac using pyenv

Tags

ai alerting aws b2 backblaze certificate cheatsheet cloud commands data-science datalake devops dns docker dremio git gitlab infra jenkins kubernetes linux metabase minikube minio monitoring mount mysql nginx nodejs notebooks openssh php python scala secrets spark ssh ssl ubuntu ufw usb web dev tools windows xampp zeppelin

©2026 Techeons | Design: Newspaperly WordPress Theme