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看出 java

docker images
docker image ls
docker image list

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

获取镜像

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进行。ubuntu

例如
搜索 niweigede 就会得到如下结果bash

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

获取镜像还能够使用docker pull命令ssh

删除镜像

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。tcp

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

运行镜像

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

run命令下的OPTIONS比较多,这里不彻底罗列,须要的请自行查询。ui

运行镜像并进入控制台

docker run -i -t niweigede/ujava:1.1

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

创建与宿主机器网络的端口映射

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.
相关文章
相关标签/搜索