Docker Cheat Sheet
Images
Build image
| docker build .
docker build -t {tag_name} .
docker build -t {tag_name} Dockerfile
|
List all images
Remove image
| docker rmi {image_name:tag_name}
|
Download image
Containers
List containers
| docker ps # show running containers
docker ps -a # show all container
|
Get logs
| docker logs [-f/--follow] {container}
|
Delete container
Run container
| docker run {image}
docker run -ti ubuntu:latest # -ti = terminal keyboardInteractive
docker run -d -ti ubuntu bash # -d : (detach) run docker process in background
docker run -e "DB_HOST=db" -e "DB_PORT=3306" -e "DB_USER=wikijs" -e "DB_PASS=wikijsrocks" image_name
docker run --name {container_name} -p {host_port}:{container_port} -v {/host_path}:{/container_path} -it {image_name} /bin/bash
|
docker run command = docker create command + docker start command
| docker create ubuntu:latest
docker start {container}
|
Inspect container
| docker inspect {container}
|
Stop container
Convert detach mode to attach mode
| docker attach {container}
|
Remove stopped contains
| docker system prune # Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
|
Executing Commands
| docker exec -it {container} sh
|
Copy file from host to container
| docker cp foo.txt mycontainer:/foo.txt
|
Copy file from container to host
| docker cp mycontainer:/foo.txt foo.txt
|
For more information, please refer here