# Docker Setup - `sudo apt install docker.io` - downloads docker ce - `sudo docker` to check if docker engine and CLI is available - `sudo docker version` to show docker client (CLI) and server (engine/host) version info - `sudo service docker status` to check docker daemon's status # Image Mgmt - `sudo docker images` to show local images that are available ![[images/Pasted image 20250822084148.png]] - go to hub.docker.com to search for docker images (official site) - `sudo docker pull image_name` to download image - docker is hard-coded to pull from hub.docker.com by default unless a different repository is specified - `sudo docker rmi -f image_name` to forcibly remove image - `sudo docker tag old_image_name new_image_name` to rename an image - able to create repository (collection of docker images) on hub.docker after creating an account # Creating a Container - `sudo docker run -it image_name` to create an container based on provided image with interactive and pseudo-TTY options - `sudo docker run -itd image_name`to create an container based on provided image with an interactive terminal and detach (based on -d flag) # Managing Existing Containers - `sudo docker ps -a` to show running containers and recently exited ones (based on the -a flag) ![[images/Pasted image 20250822084247.png]] - `sudo docker start -i container_name/id` to restart an exited container with interactive option - `sudo docker rm container_name/id` to remove a container - `sudo docket inspect container_name/id` to show details for container - `sudo docker rename old_container_name new_container_name` - `sudo docker commit target_container_name/id repository_name:tag_name` creates a new image based on changes to target container - `sudo docker exec container_name/id command` runs command against a running container ![[images/Pasted image 20250822093507.png]] - `sudo docker exec -it container_name/id /bin/bash` to run `/bin/bash` command against running container with interactive and pseudo-TTY options![[images/Pasted image 20250822084638.png]] - `sudo docker attach container_name/id` creates a session to an running container ![[images/Pasted image 20250822084455.png]] # Docker cleanup - `docker system prune` prunes docker networks, images, and containers - `docker images prune` removes dangling images - `docker container prune` removes dangling containers # Complex Container Creation - `sudo docker run -p 80:80 caddy&` to create a caddy container on localhost:80 as a background process (based on the &) - alternatively run `docker run -p 80:80 -d caddy` to run caddy on localhost:80 as a daemon (based on the -d flag) - `sudo docker run --name mysqltest1 -e MYSQL_ROOT_PASSWORD=xxx mysql:latest` to run mysql image with latest tag from hub.docker with name mysqltest1 and with specified password - `sudo docker stop mytestsql1` to stop the mysql container - run a container with VNC access - TODO