docker 命令

Last updated on November 20, 2024 am

🧙 Questions

☄️ Ideas

docker-compose

sudo yum install -y docker-compose
# 启动
docker-compose up -d
# 停止
docker-compose stop
# 删除
docker-compose rm -v
# 查看日志
docker-compose logs -f

镜像操作

拉取镜像
docker pull registry.cn-hongkong.aliyuncs.com/ispong/blogs-galaxy:[镜像版本号]
docker pull registry.docker-cn.com/dtopensource/taier:latest
推送镜像
docker tag [ImageId] registry.cn-hongkong.aliyuncs.com/ispong/blogs-galaxy:[镜像版本号]
docker push registry.cn-hongkong.aliyuncs.com/ispong/blogs-galaxy:[镜像版本号]
打包镜像

docker build -t ${groupName}/${projectName}:${versionName} -f ${dockerfilePath} .

docker build -t isxcode/nginx-and-jdk:0.0.1 -f ./Dockerfile  .
查看镜像
docker images -a
docker images -f=reference='${imageName}'
删除镜像
docker rmi ${imageId}

容器操作

创建容器
docker run --restart=always \
           --name spark-star \
           -v /opt/homebrew/Cellar/hadoop/3.3.4/libexec:/opt/hadoop/ \
           -v /opt/homebrew/opt/apache-spark/libexec:/opt/spark \
           -p 8899:80 \
           -p 8888:8080 \
           -d isxcode/spark-star:0.0.1
查看容器
docker ps -a 
docker ps -f name=${containName}
停止容器
docker stop ${containId}
docker stop ${containName}
删除容器
docker rm ${containId}
查看容器日志
docker logs -f 
docker logs -f --tail=100 e8d118c45513
docker logs -f --tail=100 ${containId}
进入容器中
docker exec -it ${containId} /bin/bash
# or
docker exec -it ${containName} /bin/bash
登录远程仓库
docker login --username=ispong registry.cn-hongkong.aliyuncs.com
查看失败容器日志
cd /data/docker/containers/
构建镜像
# 构建多平台镜像
docker buildx install
docker buildx create --name spark-yun-builder
docker buildx use spark-yun-builder
docker buildx build --platform linux/amd64,linux/arm64/v8 -t isxcode/zhiqingyun:alpha -f ./Dockerfile . --push

# 本地脚本 (需要先退出多平台镜像)
docker buildx uninstall
gradle docker
# 使用默认配置
docker run --restart=always --restart=on-failure:5 --name zhiqingyun -v /Users/ispong/Data/resources:/spark-yun/resources -p 30211:8080 -e ADMIN_PASSWORD=ispong123 -d isxcode/zhiqingyun:0.0.4
# 自定义配置
docker run --restart=always --name zhiqingyun -v /Users/ispong/Data/resources:/spark-yun/resources -v /Users/ispong/Data/config:/spark-yun/config -p 30211:8080 -e ADMIN_PASSWORD=ispong123 -d isxcode/zhiqingyun:0.0.4

# 远程启动
docker stop zhiqingyun
docker rm zhiqingyun
docker rmi isxcode/zhiqingyun:latest
docker run --restart=always --name zhiqingyun -p 30211:8080 -e ADMIN_PASSWORD=123456 -d isxcode/zhiqingyun:alpha

docker build -t isxcode/zhiqingyun:0.0.4 -f ./Dockerfile .
清理docker
docker system df
docker system prune
docker system prune --all --force --volumes
docker system df -v

# 通过overlay查询容器
cd /data/docker/containers/
ls -la
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Id}}, {{.Name}}, {{.GraphDriver.Data.WorkDir}}' | grep "ccd63593c84ec766850ceec60f1486802d911dfc7c5b8847fd3f44fae8da2be3"
清理docker的日志
cd /data/docker/containers/
sudo du -h --max-depth=1 /data/docker/containers/
cd ccd63593c84ec766850ceec60f1486802d911dfc7c5b8847fd3f44fae8da2be3
cat /dev/null > *-json.log
docker查看镜像配置
docker inspect xxxxx
容器中查看端口号
ss -tuln

docker 命令
https://ispong.isxcode.com/kubernetes/docker/docker 命令/
Author
ispong
Posted on
March 9, 2021
Licensed under