Docker
For Debian: https://docs.docker.com/engine/install/debian/
Installation
Requirements
sh
sudo apt update
sudo apt install -y ca-certificates curl gnupg
Add repository
sh
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install docker dependencies
sh
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enable and start docker
sh
sudo systemctl enable docker
sudo systemctl start docker
Check if docker is running
sh
sudo systemctl status docker
Cheatsheet
Docker
docker ps
: list containersdocker ps -a
: list all containersdocker --version
: show versiondocker images
: list imagesdocker rm [ID]
: remove containerdocker rmi [ID]
: remove imagedocker run -it [IMAGE]
: run imagedocker run -it --rm [IMAGE]
: run image and remove it after exitdocker run -it --rm -v [HOST_PATH]:[CONTAINER_PATH] [IMAGE]
: run image and mount volumedocker run -it --rm -v [HOST_PATH]:[CONTAINER_PATH] -p [HOST_PORT]:[CONTAINER_PORT] [IMAGE]
: run image and mount volume and expose port
Docker Compose
docker-compose up
: start containersdocker-compose up -d
: start containers in backgrounddocker-compose down
: stop containersdocker-compose down -v
: stop containers and remove volumesdocker-compose logs
: show logsdocker-compose logs -f
: show logs in real timedocker-compose exec [SERVICE] [COMMAND]
: execute command in servicedocker-compose exec [SERVICE] sh
: execute shell in servicedocker-compose exec [SERVICE] bash
: execute bash in servicedocker-compose exec [SERVICE] mysql -u [USER] -p
: execute mysql in service
Options
Allow non-root user to run docker
sh
sudo gpasswd -a $USER docker
newgrp docker
Login to Docker Hub
sh
sudo docker login