Docker不常用命令
Docker官方命令行文档
显示正常退出的容器
docker ps -a --filter 'exited=0'
删除已退出的容器
docker rm $(docker ps --filter status=exited -q)
删除没有tag的镜像,如 none:none形式的镜像
docker rmi $(docker images -f "dangling=true" -q)
使用Dockerfile编译镜像
# 注意最后有个 .
docker build -t ${tag} .
使用docker buildx 打包多架构镜像
docker buildx build --platform linux/arm64 -t ${image-tag} -o type=local,dest=.docker -f ./Dockerfile .
查看日志
实时查看
docker logs -f ${containerId}
最后1000行
docker logs --tail 1000 ${containerId}
保存日志
到文件,要使用>&复制,而不是>>
docker logs -t --since='2021-01-07T12:00:00' --until='2021-01-08T01:00:00' ${containerId}>& ./error.log
使用docker-compose部署docker service
docker stack deploy -c docker-compose.yml ${栈名}
根据service name推断container name
container_name=$(docker ps --filter "label=com.docker.swarm.service.name=${serviceName}" --format "{{.Names}}")