Docker

**************************************************************  DOCKER  *****************************************************************
 
INSTALLATION:
 
# sudo apt-get remove docker docker-engine docker.io containerd runc // remove old versions
# sudo apt update // update repositories
# sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release // packages that allow apt to use repos over HTTPS
 
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg // add GPG key (Docker)
 
 
********************************************  Adding repository and images ***************************
 
echo "deb [arch=$(dpkg --print-architecture) 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
// adding Docker repository for ubuntu to apt list
 
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
// adding Docker repository for debian to apt list
 
# sudo rm /etc/apt/sources.list.d/docker.list // removing wrong repository
 
# sudo apt update
# sudo apt install docker-ce docker-ce-cli containerd.io // install more packages
# sudo docker run hello-world // run test if docker is configured correctly
 
# docker images // list local images
# docker search <package_name> // look for specific package in Docker Hub
 
********************************************  Managing containers  *************************
 
# docker ps // list running containers
# docker ps -a // list all containers
 
# docker start <container_name_or_ID> // starts container
# docker stop <container_name_or_ID> // gracefully stops container
# docker restart <container_name_or_ID> // restarts container
 
# docker inspect <container_name_or_ID> // detailed JSON output about a container’s configuration and state
# docker rm <container_name_or_ID> // removes container, use -f to force
 
# docker exec -it <container_name_or_ID> bash // opens an interactive shell inside specified container
 
 
********************************************  Client / Host operations  *************************
 
# docker cp [OPTIONS] <source_path> <destination_path> // copying files between container and host
# docker cp my_container:/app/config.yaml /home/user/config.yaml // example container -> host
# docker cp /home/user/new_script.sh my_container:/app/scripts/ // exmaple host -> container
 
# docker attach <container_name_or_ID> // attach your terminal to the container’s standard input, output, and error streams