Skip to content

Instantly share code, notes, and snippets.

@JustinTW
Last active May 25, 2017 08:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinTW/10236453 to your computer and use it in GitHub Desktop.
Save JustinTW/10236453 to your computer and use it in GitHub Desktop.
Docker Cheatsheets

Clean all

docker stop `docker ps -a -q` 
docker rm `docker ps -a -q` 
docker rmi -f `sudo docker images -q`
docker volume rm $(docker volume ls -f dangling=true -q)

Clean image

docker images --no-trunc | grep none | awk '{print $3}' | xargs docker rmi -f

Change docker image location

btrfs subvolume create /mnt/disk/@docker
rsync -aqxP /var/lib/docker/* /mnt/disk/@docker
  • method 1: 變更 docker 儲存路徑
sudo vi /etc/docker/daemon.json
{
  "registry-mirrors":["https://cache-docker.hopebaytech.com"],
  "insecure-registries":["docker:5000"],
  "dns":["172.16.1.254", "8.8.8.8"],
  "graph": "/mnt/disk/docker",
  "storage-driver": "btrfs"
}

重新啟動服務

sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker

附註

啟動設定檔位置

/etc/docker/daemon.json
/etc/default/docker
/etc/systemd/system/docker.service.d/docker.conf

Attach a running container

# list containers
docker ps -a

# attach a running containers
docker attach [CONTAINER ID]

# attach a running containers into bash
docker exec -i -t arkease-pro-web bash
#!/bin/bash
docker stop `docker ps -a -q`
docker rm `docker ps -a -q`
docker rmi -f `sudo docker images -q`
docker volume rm $(docker volume ls -f dangling=true -q)
read -rsp $'Press any key to continue...\n' -n1 key
btrfs subvolume list /mnt/disk
service docker stop
read -rsp $'Press Ensure there are no usless subvolume...\n' -n1 key
cd /mnt/disk
btrfs subvolume delete docker
btrfs subvolume create docker
rsync -aqxP /var/lib/docker/* docker
service docker start
btrfs subvolume list /mnt/disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment