Skip to content
docker_cover

Docker实用命令

实习中项目有用到docker将Java打成镜像,方便项目部署,也方便了交付。这里总结了一些常用的docker命令,方便以后查看~

docker命令官方地址

查看本地仓库镜像
shell
docker images
查询远程仓库镜像
shell
docker search <repository>
e.g. docker search redis
拉取远程仓库镜像
shell
docker pull <repository>:<tag> 
e.g.docker pull redis:lastest
删除本地仓库镜像
shell
docker rmi <image-id>
运行容器
shell
#后台运行一个镜像为image-id(或repository名:tag)的docker容器
docker run -d -it <image-id> /bin/bash
#挂载宿主目录到容器内部指定目录
#主机ip端口映射到容器内部
docker run -d -it 
-v <host-absolute-path>:<container-absolute-path> 
-p <ip>:<host-port>:<container-port> (不常用)
-p <ip>::<container-port> (不常用)
-p <host-port>:<container-port> (常用)
<image-id> /bin/bash
进入容器内部
shell
docker exec -it <container-id> /bin/bash
docker attach <container-id>
查看镜像实例
shell
docker ps 
docker ps -n <num>
停止正在运行的容器实例
shell
docker stop <container-id>
启动停止的容器实例
shell
docker start <container-id>
删除容器实例
shell
docker rm <container-id>
镜像打包
shell
docker commit 
-a <author-name> 
-m <commit-message> 
<container-id>|<container-name>
<package-image-name>:<package-image-tag>

docker commit command

镜像导出
docker save <image-id> > host-absolute-path/file-name
镜像加载
docker load < host-absolute-path/file-name
镜像打标签
shell
docker tag <image-id> <repository>:<tag>