docker镜像与容器的基本操作

镜像操作

docker images 参数

-a, --all 显示所有详细信息
–digests 显示摘要
-f, --filter filter Filter output based on conditions provided
–format string Pretty-print images using a Go template
–no-trunc Don’t truncate output
-q, --quiet Only show numeric IDs

  • 显示所有镜像

docker images

  • 删除镜像

docker rm image1 image2

  • 获取镜像

docker pull ubuntu:13.10

  • 查找镜像

docker seacrh python

  • 通过镜像创建一个容器

docker run -it runoob/ubuntu:v2 /bin/bash

-i 表示以“交互模式”运行容器
-t 表示容器启动后会进入其命令行。加入这两个参数后,容器创建就能登录进去。即 分配一个伪终端。
–name 为创建的容器命名
-v 表示目录映射关系(前者是宿主机目录,后者是映射到宿主机上的目录,即 宿主机目录:容器中目录),可以使 用多个-v 做多个目录或文件映射。注意:最好做目录映射,在宿主机上做修改,然后 共享到容器上。
-d 在run后面加上-d参数,则会创建一个守护式容器在后台运行(这样创建容器后不 会自动登录容器,如果只加-i -t 两个参数,创建后就会自动进去容器)。
-p 表示端口映射,前者是宿主机端口,后者是容器内的映射端口。可以使用多个-p 做多个端口映射
-e 为容器设置环境变量
–network=host 表示将主机的网络环境映射到容器中,容器的网络与主机相同

  • 保存镜像

docker save -o 保存的文件名,以.tar结尾 镜像名

  • 加载镜像

docker load -i ./xxx.tar

  • 镜像重命名

docker tag 镜像ID 新名:版本号

容器操作

docker container 参数

commandinstruction
attachAttach local standard input, output, and error streams to a running container
commitCreate a new image from a container’s changes
cpCopy files/folders between a container and the local filesystem
createCreate a new container
diffInspect changes to files or directories on a container’s filesystem
execRun a command in a running container
exportExport a container’s filesystem as a tar archive
inspectDisplay detailed information on one or more containers
killKill one or more running containers
logsFetch the logs of a container
lsList containers
pausePause all processes within one or more containers
portList port mappings or a specific mapping for the container
pruneRemove all stopped containers
renameRename a container
restartRestart one or more containers
rmRemove one or more containers
runRun a command in a new container
startStart one or more stopped containers
statsDisplay a live stream of container(s) resource usage statistics
stopStop one or more running containers
topDisplay the running processes of a container
unpauseUnpause all processes within one or more containers
updateUpdate configuration of one or more containers
waitBlock until one or more containers stop, then print their exit codes
  • 显示所有容器

docker container ls --all

  • 显示运行中的容器

docker ps

  • 删除容器

docker rm 容器id

  • 查看标准输出

docker logs [ID或者名字]

  • 启动,停止,重启

docker start stop restart

  • 打包容器成为一个镜像

docker commit -m=“描述信息” -a=“作者” 容器ID 镜像名

将镜像推送到远端仓库(阿里云)

# 登陆至阿里云
sudo docker login --username=阿里云用户名 registry.cn-beijing.aliyuncs.com
sudo docker tag [ImageId] registry.cn-beijing.aliyuncs.com/trs_wangfei/python3.6.8:[镜像版本号]
$ sudo docker push registry.cn-beijing.aliyuncs.com/trs_wangfei/python3.6.8:[镜像版本号]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值