docker常用指令

整理的一些常用指令

指令解释
docker version#查看版本
docker search centos#搜索可用 docker 镜像
systemctl start docker#启动
systemctl daemon-reload#守护进程重启
systemctl restart docker#重启docker服务
systemctl stop docker#关闭docker
docker images#查看当前 docker 所有镜像
docker pull centos#下载镜像
cat centos.tardocker import - centos6
docker export id > cenos6.tar#Docker 导出镜像,可以直接导出压缩包
docker run centos echo “hello word”#在 docker 容器中运行 hello world!
docker run centos yum install ntpdate#在容器中安装 ntpdate 的程序
docker ps -l#命令获得最后一个容器的 id,docker ps -a 查看所有的容器。
docker commit 容器id centos:v1#运行 docker commit 提交刚修改的容器,大改建议用dockerfile进行
docker commit -a 作者名 -m “备注” 正运行的容器id 起个版本更新后的镜像名#一定要是正在运行的容器,然后ctrl+p+q进入后台运行,再提交修改
docker run -it imagesName:tag bash#在容器里启动一个/bin/bash shell 环境,可以登录进入操作,其中-t 表示打开一个终端的意思,-i 表示可以交互输入。
docker run -d imagesName:tag /bin/bash#-d 表示在后台启动,以 daemon 方式启动。
docker ps -a#查看当前后台运行的容器
docker attach 容器id#进入到后台运行的容器中去
docker run -d -p 80:80 -p 8022:22 centos:v2#解析:-p 指定容器启动后 docker 上运行的端口映射及容器里运行的端口,80:80,第一个 80 表示docker 系统上的 80,第二个 80 表示 docker 虚拟机里面的端口。用户默认访问本机 80 端口,自动映射到容器里面的 80 端口。
docker stop id#关闭容器
docker start id#启动某个容器
docker restart myrunoob#重启某个容器
docker rm id#删除容器,docker rmi images 删除镜像
docker save -o filename.tar filename#将filename压缩为filename.tar output
docker load -i filename.tar#加载镜像 input

docker帮助文档

A self-sufficient runtime for containers

docker Commands:解释
builderManage builds
checkpointManage checkpoints
configManage Docker configs
containerManage containers
engineManage the docker engine
imageManage images
manifestManage Docker image manifests and manifest lists
networkManage networks
nodeManage Swarm nodes
pluginManage plugins
secretManage Docker secrets
serviceManage services
stackManage Docker stacks
swarmManage Swarm
systemManage Docker
trustManage trust on Docker images
volumeManage volumes
attachAttach local standard input, output, and error streams to a running container
buildBuild an image from a Dockerfile
commitCreate a new image from a container’s changes
cpCopy files/folders between a container and the local filesystem
createCreate a new container
deployDeploy a new stack or update an existing stack
diffInspect changes to files or directories on a container’s filesystem
eventsGet real time events from the server
execRun a command in a running container
exportExport a container’s filesystem as a tar archive
historyShow the history of an image
imagesList images
importImport the contents from a tarball to create a filesystem image
infoDisplay system-wide information
inspectReturn low-level information on Docker objects
killKill one or more running containers
loadLoad an image from a tar archive or STDIN
loginLog in to a Docker registry
logoutLog out from a Docker registry
logsFetch the logs of a container
pausePause all processes within one or more containers
portList port mappings or a specific mapping for the container
psList containers
pullPull an image or a repository from a registry
pushPush an image or a repository to a registry
renameRename a container
restartRestart one or more containers
rmRemove one or more containers
rmiRemove one or more images
runRun a command in a new container
saveSave one or more images to a tar archive (streamed to STDOUT by default)
searchSearch the Docker Hub for images
startStart one or more stopped containers
statsDisplay a live stream of container(s) resource usage statistics
stopStop one or more running containers
tagCreate a tag TARGET_IMAGE that refers to SOURCE_IMAGE
topDisplay the running processes of a container
unpauseUnpause all processes within one or more containers
updateUpdate configuration of one or more containers
versionShow the Docker version information
waitBlock until one or more containers stop, then print their exit codes

Run ‘docker COMMAND --help’ for more information on a command

docker 卷的管理

#docker-managed volume自管理卷
docker run -it --name <name> -v <mountdir> <image:version>
docker inspect -f {{.Mounts}} <imagename>

自管理卷需要在打镜像的时候就定义好挂载点(持久化存储)格式为
VOLUME dir

#bind-mount volume
docker run -it --name <name> -v <hostdir:volumedir > <image:version>
#union volume
docker run -it --name <name> --volumes-from <containName> <image:version>

docker 容器之间实现文件共享

方法一:使用nfs
方法二:通过宿主机同一个卷实现数据同步

docker run --name test01 -v /data:/var -d test:v1.0
docker run --name test02 -v /data:/var -d test:v1.0

方法三:使用union volume联合卷
不使用宿主机实现共享:在启动第二个容器时声明使用第一个容器的卷,需要第一个容器使用自管理卷(docker-managed volume)实现持久化存储。

docker run --anme test2 -d test:v2.0#默认test:v2.0打镜像已经实现了自管理卷
dicker run --name test22 -d --volumes  -from test2 -d test:v2.0

这里创建的test22就是使用test2的卷,实现了容器共享

删除持久画卷

删除容器的时候默认不删除持久化卷,如果想删除持久化卷,就加个参数-v

docker rm -rf -v test2

存储驱动

docker info3#查看信息

如果不是overlay,建议更改为overlay,更改方式为:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值