docker鏡像管理

鏡像是什麼 簡單來講docker鏡像是一個不包含linux內核而又精簡的linux操做系統。 鏡像從哪裏來 docker hub是由docker公司負責維護的公共註冊中心,包含大量的容器鏡像,docker工具默認從這個鏡像庫下載鏡像。https://hub.docker.com/explore 默認國外源,下載較慢,建議配置國內鏡像倉庫: vim /etc/docker/daemon.json { "registry-mirrors":["https://registry.docker-cn.com"] } 重啓docker生效 [root@docker docker]# systemctl restart docker [root@docker docker]# docker pull busybox Using default tag: latest latest: Pulling from library/busybox 53071b97a884: Pull complete Digest: sha256:4b6ad3a68d34da29bf7c8ccb5d355ba8b4babcad1f99798204e7abb43e54ee3d Status: Downloaded newer image for busybox:latest [root@docker docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 62c261073ecf 2 days ago 109MB busybox latest 64f5d945efcc 4 weeks ago 1.2MB 鏡像與容器聯繫 鏡像不是一個單一的文件,而是有多層構成。咱們能夠經過docker history<ID/NAME>查看鏡像中各層內容及大小,每層對應着dockerfile中的一條指令。docker鏡像默認存儲在/var/lib/docker/ 中。 容器實際上是在鏡像的最上面加了一層讀寫層,在運行容器裏作的任何文件改動,都會寫到這個讀寫層。若是容器刪除了,最上面的讀寫層也就刪除了,改動也就丟失了。 docker使用存儲驅動管理鏡像每層內容及可讀寫層的容器層。 node

[root@docker docker]# docker history nginx IMAGE CREATED CREATED BY SIZE COMMENT 62c261073ecf 2 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
2 days ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
2 days ago /bin/sh -c #(nop) EXPOSE 80 0B
2 days ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B
2 days ago /bin/sh -c set -x && addgroup --system -… 54MB
2 days ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~stretch 0B
2 days ago /bin/sh -c #(nop) ENV NJS_VERSION=0.3.2 0B
2 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.17.0 0B
4 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
4 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B
4 weeks ago /bin/sh -c #(nop) ADD file:fcb9328ea4c115670… 55.3MB
[root@docker docker]# ls builder buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes 鏡像管理命令 [root@docker docker]# docker help
linux

Usage: docker [OPTIONS] COMMANDnginx

A self-sufficient runtime for containersdocker

Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quitjson

Management Commands: builder Manage builds config Manage Docker configs container Manage containers engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumesvim

Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codesbash

Run 'docker COMMAND --help' for more information on a command. [root@docker docker]# docker image helpapp

Usage: docker image COMMANDsocket

Manage imagestcp

Commands: build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Run 'docker image COMMAND --help' for more information on a command. [root@docker docker]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 62c261073ecf 2 days ago 109MB busybox latest 64f5d945efcc 4 weeks ago 1.2MB [root@docker docker]# docker image history busybox IMAGE CREATED CREATED BY SIZE COMMENT 64f5d945efcc 4 weeks ago /bin/sh -c #(nop) CMD ["sh"] 0B
4 weeks ago /bin/sh -c #(nop) ADD file:e36dd1822f36a8169… 1.2MB
查看鏡像信息 [root@docker docker]# docker image inspace

Usage: docker image COMMAND

Manage images

Commands: build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Run 'docker image COMMAND --help' for more information on a command. [root@docker docker]# docker image inspect nginx [ { "Id": "sha256:62c261073ecffe22a28f2ba67760a9320bc4bfe8136a83ba9b579983346564be", "RepoTags": [ "nginx:latest" ], "RepoDigests": [ "nginx@sha256:12db363acf5b2d2f9f5fed240e228a04692bdac68402430fbd2f720c3a967d01" ], "Parent": "", "Comment": "", "Created": "2019-06-04T22:29:15.22271163Z", "Container": "6e81d902bf0b5631099c0789d2573a348a26649a73391e67fa4b14545f6de200", "ContainerConfig": { "Hostname": "6e81d902bf0b", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "80/tcp": }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "NGINX_VERSION=1.17.0", "NJS_VERSION=0.3.2", "PKG_RELEASE=1stretch" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD ["nginx" "-g" "daemon off;"]" ], "ArgsEscaped": true, "Image": "sha256:b4c546a22099dc546c525e66dd7bbf40bc183195a0559d418b04057cbe363792", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "maintainer": "NGINX Docker Maintainers docker-maint@nginx.com" }, "StopSignal": "SIGTERM" }, "DockerVersion": "18.06.1-ce", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "80/tcp": }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "NGINX_VERSION=1.17.0", "NJS_VERSION=0.3.2", "PKG_RELEASE=1stretch" ], "Cmd": [ "nginx", "-g", "daemon off;" ], "ArgsEscaped": true, "Image": "sha256:b4c546a22099dc546c525e66dd7bbf40bc183195a0559d418b04057cbe363792", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "maintainer": "NGINX Docker Maintainers docker-maint@nginx.com" }, "StopSignal": "SIGTERM" }, "Architecture": "amd64", "Os": "linux", "Size": 109258871, "VirtualSize": 109258871, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/cc87902e3a53ec2d035789fd293dd20d3f2c5483c36ded801dde84567abf8b9e/diff:/var/lib/docker/overlay2/a5fe97da169a47defdb199e3b1ef5ef50702864f57998b2b4958e38ca4150ccc/diff", "MergedDir": "/var/lib/docker/overlay2/c5e5d61d04d7659136d27a78a17b2bdc66f6a01d48d33da7872d0ad056387961/merged", "UpperDir": "/var/lib/docker/overlay2/c5e5d61d04d7659136d27a78a17b2bdc66f6a01d48d33da7872d0ad056387961/diff", "WorkDir": "/var/lib/docker/overlay2/c5e5d61d04d7659136d27a78a17b2bdc66f6a01d48d33da7872d0ad056387961/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:6270adb5794c6987109e54af00ab456977c5d5cc6f1bc52c1ce58d32ec0f15f4", "sha256:22c458a3ff08c2249c2362281035476427dd84ae6c4d12a14e1f79e7ae325eba", "sha256:ea06a73e56fce0a3293829c54bedc2f77d88c4d5951ff1acd59ee1507ad2ed7f" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ] 編輯標籤 [root@docker ~]# docker tag nginx:latest nginx:v1 查看鏡像列表 [root@docker ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 62c261073ecf 2 days ago 109MB nginx v1 62c261073ecf 2 days ago 109MB busybox latest 64f5d945efcc 4 weeks ago 1.2MB 刪除鏡像 [root@docker ~]# docker image rm nginx:v1 Untagged: nginx:v1 [root@docker ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 62c261073ecf 2 days ago 109MB busybox latest 64f5d945efcc 4 weeks ago 1.2MB 保存鏡像 [root@docker ~]# docker image save nginx:latest >nginx_latest.tar [root@docker ~]# du -sh nginx_latest.tar 108M nginx_latest.tar [root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e8c8d5983eef busybox "sh" 51 seconds ago Up 50 seconds naughty_poitras 導出鏡像 [root@docker ~]# docker export e8c8d5983eef > busybox.tar [root@docker ~]# du -sh busybox.tar 1.4M busybox.tar 導入鏡像 [root@docker ~]# docker image import busybox.tar busybox:busybox_testsha256:c31d10bdde73e9355e9b499cf94022f522ac8d0613139ab4d70608a6c76c52a7 [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox busybox_test c31d10bdde73 14 seconds ago 1.2MB nginx latest 62c261073ecf 2 days ago 109MB busybox latest 64f5d945efcc 4 weeks ago 1.2MB nginx 1.12 4037a5562b03 13 months ago 108MB export:導出容器文件系統到tar歸檔文件。 save:保存一個或多個鏡像到一個tar歸檔文件。

相關文章
相關標籤/搜索