Docker 相关 (问题 & 常用命令)
声明
本文版权归原作者所有,未经允许禁止转载。
换源 & pull 断点续传
可用且速度还不错的国内源列举:
https://hub.mirrorify.net
https://docker.1ms.run
https://docker.m.daocloud.io
一条命令:
tee /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://hub.mirrorify.net"],
"features": {
"containerd-snapshotter": true
},
"default-ulimits": {
"nofile": {
"Name": "nofile","Hard": 65535,"Soft": 65535}
}
}
EOF
service docker restarttee /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://docker.1ms.run"],
"features": {
"containerd-snapshotter": true
},
"default-ulimits": {
"nofile": {
"Name": "nofile","Hard": 65535,"Soft": 65535}
}
}
EOF
service docker restarttee /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://docker.yinsel.top"],
"features": {
"containerd-snapshotter": true
},
"default-ulimits": {
"nofile": {
"Name": "nofile","Hard": 65535,"Soft": 65535}
}
}
EOF
service docker restarttee /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://docker.m.daocloud.io"],
"features": {
"containerd-snapshotter": true
},
"default-ulimits": {
"nofile": {
"Name": "nofile","Hard": 65535,"Soft": 65535}
}
}
EOF
service docker restart常用命令
端口映射时绑定 IP
docker run -d -p 127.0.0.1:8000:80 nginx
进入容器终端
docker exec -it <容器ID> /bin/bash
停止全部容器
docker stop $(docker ps -q)
删除全部容器
docker rm $(docker ps -aq)
删除全部镜像
docker rmi $(docker images -q)
停止并删除全部容器
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)
查看容器 PID
docker inspect -f '{{.State.Pid}}' <ID>
查看容器 IP 地址
docker inspect <ID> | grep IPAddress
导出镜像
# 包括镜像名及tag,原封不动导出
docker save -o image.zip <image>:<tag>
导入镜像
docker load -i image.zip
# 恢复标签
docker image tag <image-ID> <name>:tag
删除无用卷
docker volume prune -f