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: