docker命令行随记
CentOS部署
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
编译
docker build -t project:tag .
docker-compose up --build
查看镜像
docker ps
docker exec -it 4fbcedb50e0e /bin/sh
镜像操作
docker ps -a --filter ancestor=container_id
docker stop container_id
docker rm container_id
清除缓存
docker system prune -a
docker container prune
docker image prune -a
创建网络
docker network create satellite_local_network
docker network ls
镜像文件使用
// /etc/docker/daemon.json
{
"registry-mirrors": ["https://7tld9g66.mirror.aliyuncs.com"]
}
科大镜像 https://docker.mirrors.ustc.edu.cn
集合 https://gist.github.com/y0ngb1n/7e8f16af3242c7815e7ca2f0833d3ea6
docker长时间使用占用大量磁盘空间,定期清理磁盘
// 查看磁盘空间
df -h
// 清理无用容器
docker container prune
// 清理未使用镜像
docker image prune -a
// 清理未使用网络
docker network prune
// 清理未使用卷
docker volume prune
// 一键清理未使用资源
docker system prune -a
docker-compose配置
// 镜像
{
"registry-mirrors": [
"https://paucfus3.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"https://registry.aliyuncs.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
// 重启服务
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl start docker
systemctl enable docker
// 下载
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version