Docker Basics in Linux
Posted on June 1, 2024 (Last modified on June 8, 2024) • 2 min read • 263 wordsGet started with Docker in Linux, including installing Docker, managing containers, and using Docker Compose for multi-container applications.
Docker is a powerful tool for containerization. This guide covers getting started with Docker in Linux, including installing Docker, managing containers, and using Docker Compose for multi-container applications.
Install Docker using the convenience script.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Set up the Docker repository.
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install Docker Engine.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Use docker run
to start a container.
docker run hello-world
List running containers.
docker ps
List all containers, including stopped ones.
docker ps -a
Stop a running container.
docker stop container_id
Remove a stopped container.
docker rm container_id
View logs of a container.
docker logs container_id
Install Docker Compose.
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Create a docker-compose.yml
file.
version: '3'
services:
web:
image: nginx
ports:
- "80:80"
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
Start the application using Docker Compose.
docker-compose up
Stop the application.
docker-compose down
Getting started with Docker in Linux involves installing Docker, managing containers, and using Docker Compose for multi-container applications. Practice these basics to effectively use Docker in your development and deployment workflows.