image有几种获取方式:
1、Docker官方提供了一种文件格式:Dockerfile,通过这种格式的文件,我们可以定义一个image,然后通过Dockerfile我们可以构建(build)一个image
2、通过registry拉去image
PS:registry 是docker提出的一个概念,有些像github,我们可以从github上 clone软件,也可以通过push把软件推到github上,供其他人使用,在docker里借鉴了这个概念,
我们可以通过registry拉取我们需要的image,也可以push到registry上面。
(1)docker hub 是docker免费提供的registry,我们用docker命令获取image 默认是docker hub(https://hub.docker.com/),如果是pull 拉取,不需要注册用户,如果要push则需要。
在docker hub上面可以search搜索有哪些image
(2)docker提供的image分两类,一种是docker官方提供的 带official images,另一种是个人提供的,比如Ubuntu image,有多个版本,通过docker pull ubuntu 则默认下载最新版本image,也可以通过tags,加上版本
(3)除了docker官方提供的image,还有第三方提供的image,通过pull获取时,需加上用户名比如
docker pull scrapybook/dev
取ubuntu14.04
如果不指定tag 默认下载最新版本 latest
[root@localhost ~]# doucker pull ubuntu:14.04 bash: doucker: command not found... Similar command is: 'docker' [root@localhost ~]# docker pull ubuntu:14.04 14.04: Pulling from library/ubuntu a7344f52cb74: Pull complete 515c9bb51536: Pull complete e1eabe0537eb: Pull complete 4701f1215c13: Pull complete Digest: sha256:2f7c79927b346e436cc14c92bd4e5bd778c3bd7037f35bc639ac1589a7acfa90 Status: Downloaded newer image for ubuntu:14.04 [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 14.04 2c5e00d77a67 7 weeks ago 188MB hello-world latest fce289e99eb9 6 months ago 1.84kB [root@localhost ~]#
搜索一个镜像
[root@localhost network-scripts]# docker search alpine NAME DESCRIPTION STARS OFFICIAL AUTOMATED alpine A minimal Docker image based on Alpine Linux… 7428 [OK] mhart/alpine-node Minimal Node.js built on Alpine Linux 484 anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.28 over A… 469 [OK] frolvlad/alpine-glibc Alpine Docker image with glibc (~12MB) 259 [OK] alpine/git A simple git container running in alpine li… 177 [OK] mvertes/alpine-mongo light MongoDB container 117 [OK] yobasystems/alpine-mariadb MariaDB running on Alpine Linux [docker] [am… 89 [OK] alpine/socat Run socat command in alpine container 68 [OK] kiasaki/alpine-postgres PostgreSQL docker image based on Alpine Linux 44 [OK] jfloff/alpine-python A small, more complete, Python Docker image … 41 [OK] byrnedo/alpine-curl Alpine linux with curl installed and set as … 34 [OK] hermsi/alpine-sshd Dockerize your OpenSSH-server with rsync and… 33 [OK] zenika/alpine-chrome Chrome running in headless mode in a tiny Al… 33 [OK] hermsi/alpine-fpm-php FPM-PHP 7.0 to 8.0, shipped along with tons … 25 [OK] etopian/alpine-php-wordpress Alpine WordPress Nginx PHP-FPM WP-CLI 24 [OK] bashell/alpine-bash Alpine Linux with /bin/bash as a default she… 18 [OK] roribio16/alpine-sqs Dockerized ElasticMQ server + web UI over Al… 13 [OK] davidcaste/alpine-java-unlimited-jce Oracle Java 8 (and 7) with GLIBC 2.21 over A… 13 [OK] spotify/alpine Alpine image with `bash` and `curl`. 11 [OK] cfmanteiga/alpine-bash-curl-jq Docker Alpine image with Bash, curl and jq p… 6 [OK] hermsi/alpine-varnish Dockerize Varnish upon a lightweight alpine-… 3 [OK] dwdraju/alpine-curl-jq Alpine Docker Image with curl, jq, bash 1 [OK] ellerbrock/alpine-mysql-client MySQL Client based on Alpine Linux 1 [OK] goodguykoi/alpine-curl-internal simple alpine image with curl installed no C… 1 [OK] bushrangers/alpine-caddy Alpine Linux Docker Container running Caddys… 1 [OK] [root@localhost network-scripts]#
查看本地有哪些镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]# docker images ls REPOSITORY TAG IMAGE ID CREATED SIZE [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB
[root@localhost ~]# docker pull alpine:3.10 #可以指定版本 3.10: Pulling from library/alpine 396c31837116: Pull complete Digest: sha256:451eee8bedcb2f029756dc3e9d73bab0e7943c1ac55cff3a4861c52a0fdd3e98 Status: Downloaded newer image for alpine:3.10 docker.io/library/alpine:3.10 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]# docker pull docker.io/library/alpine:3.11.11 #可以填写镜像结构全称,如果不填写,则默认去docker.io里拉取。 3.11.11: Pulling from library/alpine ddad3d7c1e96: Pull complete Digest: sha256:18a918a714d1368847b67173d120ebd110fcfae208305412f3005a61cdc7c20e Status: Downloaded newer image for alpine:3.11.11 docker.io/library/alpine:3.11.11 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB alpine 3.11.11 e389ae589224 4 weeks ago 5.62MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]#
给镜像打tag(标签)
[root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB alpine 3.11.11 e389ae589224 4 weeks ago 5.62MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]# docker tag e389ae589224 docker.io/bigni/alpine:XX.XX.XXX [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB bigni/alpine XX.XX.XXX e389ae589224 4 weeks ago 5.62MB alpine 3.11.11 e389ae589224 4 weeks ago 5.62MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]#
推送到远程仓库
[root@localhost ~]# docker push docker.io/bigni/alpine:XX.XX.XXX The push refers to repository [docker.io/bigni/alpine] 9a5d14f9f550: Mounted from library/alpine XX.XX.XXX: digest: sha256:71a2b866473e26e7c3dfcd7488975ed8d8ba46c495f76a50957fc11f2d6f4dec size: 528 [root@localhost ~]
删除镜像
[root@localhost ~]# docker tag e389ae589224 docker.io/bigni/alpine:2X.XX.XXX [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB bigni/alpine 2X.XX.XXX e389ae589224 4 weeks ago 5.62MB bigni/alpine XX.XX.XXX e389ae589224 4 weeks ago 5.62MB alpine 3.11.11 e389ae589224 4 weeks ago 5.62MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB hello-world latest d1165f221234 2 months ago 13.3kB [root@localhost ~]# docker rmi docker.io/bigni/alpine:XX.XX.XXX #这个只是删除了标签 Untagged: bigni/alpine:XX.XX.XXX [root@localhost ~]# docker images|grep alpine mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB bigni/alpine 2X.XX.XXX e389ae589224 4 weeks ago 5.62MB alpine 3.11.11 e389ae589224 4 weeks ago 5.62MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB [root@localhost ~]# docker rmi e389ae589224 #通过image id 可以删除本地镜像。 Error response from daemon: conflict: unable to delete e389ae589224 (must be forced) - image is referenced in multiple repositories [root@localhost ~]# docker rmi -f e389ae589224 Untagged: bigni/alpine:2X.XX.XXX Untagged: bigni/alpine@sha256:71a2b866473e26e7c3dfcd7488975ed8d8ba46c495f76a50957fc11f2d6f4dec Untagged: alpine:3.11.11 Untagged: alpine@sha256:18a918a714d1368847b67173d120ebd110fcfae208305412f3005a61cdc7c20e Deleted: sha256:e389ae58922402a7ded319e79f06ac428d05698d8e61ecbe88d2cf850e42651d Deleted: sha256:9a5d14f9f5503e55088666beef7e85a8d9625d4fa7418e2fe269e9c54bcb853c [root@localhost ~]# docker images|grep alpine mhart/alpine-node latest 42bfa7acee09 3 weeks ago 108MB alpine 3.10 e7b300aee9f9 4 weeks ago 5.58MB alpine latest 6dbb9cc54074 4 weeks ago 5.61MB [root@localhost ~]#