docker教程—image操作

查看当前image列表

docker image ls [OPTIONS] [REPOSITORY[:TAG]]

List images

Aliases:
  ls, images, list

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show 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

从Aliases看出 

docker images
docker image ls
docker image list

三条命令都可以查看docker image列表

获取镜像

docker image pull [OPTIONS] NAME[:TAG|@DIGEST] [flags]
Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable

 Params:
  NAME                          镜像名称。镜像可以在Docker Store上查找其名称。一般是
                                user/repo:tag的格式

镜像可以通过上述命令先获取到本地。Docker的查询在Docker Store进行。

例如
搜索 niweigede 就会获得以下结果

可以看出,这个镜像的描述使用了ubuntu,java-8,ssh以及tsinghua的apt 源。

获取镜像还可以使用docker pull命令

删除镜像
docker image rm [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Aliases:
  rm, rmi, remove

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents

删除镜像时,IMAGE参数可以指定镜像名称或者镜像ID。

如果被删除的镜像A,在本地有基于A制作的镜像B,则直接删除A会报'conflict: unable to delete 5a662682895c (cannot be forced) - image has dependent child images'错误。此时需要先解除关联,也就是先删除B才能继续删除A

运行镜像
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

run命令下的OPTIONS比较多,这里不完全罗列,需要的请自行查询。

运行镜像并进入控制台
docker run -i -t niweigede/ujava:1.1

上述命令表示基于镜像niweigede/ujava:1.1打开一个新的container。其中-i表示保持一个标准输入STDIN,-t表示分配一个虚拟控制台TTY用于与container进行交互

建立与宿主机器网络的端口映射
docker run -it -p 8070:8080 niweigede/ujava:1.1

使用命令-p端口映射,详细的使用方式如下

format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
        Both hostPort and containerPort can be specified as a range of ports. 
        When specifying ranges for both, the number of container ports in the range 
        must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`)
自定义container名称
docker run -it --name CUSTOMER_NAME niweigede/ujava:1.1

使用命令--name给即将运行的container分配一个自定的名称"CUSTOMER_NAME"

添加数据卷volume挂载
docker run -it -v /home/host:/home/container niweigede/ujava:1.1

使用命令-v进行数据卷挂载,详细的使用方式如下

Create a bind mount with: [host-dir:]container-dir[:rw|ro].
       If 'host-dir' is missing, then docker creates a new volume.
       If neither 'rw' or 'ro' is specified then the volume is mounted
       in read-write mode.

转载于:https://my.oschina.net/u/3042999/blog/3067052

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值