如果你是像我一样,Docker 小白,那么在docker pull
时,很有可能会遇到和我同样的问题:
好的,那么我就来具体说说,我在下载 ubantu
$ docker pull ubantu
Using default tag: latest
Error response from daemon: pull access denied for ubantu, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
我想,现在你会看到,你遇到的问题和我的基本如出一撤。别着急,我们先来check命令docker pull ubantu
:
- 没有提供 Docker 镜像仓库地址,因此将会从 Docker Hub (
docker.io
)获取镜像 - 没有提供 tag, Docker Engine 将使用 default tag (
:latest
) - 仓库名:仓库名通常是两段式名称,即
<用户名>/<软件名>
。对于 Docker Hub,如果不给出用户名,则默认为library
,也就是官方镜像。
所以,docker pull ubantu
是从 docker.io/library/ubantu
下载 ubantu:latest
官方镜像。 (docker search ubantu
-> 没有官方镜像)
当我们去下载某个镜像时,我们肯定想知道仓库(Repository
)中是否有我们要的镜像(Image
)
很简单,run 命令:docker search ubantu
- 执行结果:显示 name 中包含
ubantu
的所有镜像 - 没有看到
DESCRIPTION
和OFFICIAL
中出现 Ubantu Base Image 和 [OK]. (docker search --filter is-official=true ubantu
)。 这就是docker pull ubantu
报错的原因,没有官方镜像
$ docker search ubantu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
boystar/ubantu Ubantu系统精简版 2
fishjerky/ubantu-mongodb 1
huangrui93/ubantu-flask 1
disuzf/ubantu 1
dhanraj91/ubantu 0
ajitsarangi/ubantu 0
xiebingmeng/ubantu 0
lclovehoro/ubantu python3.7.10 0
neertiwa/ubantu my first 0
burraharish/ubantu 0
karanmgr19/ubantu_git 0
kiransajja/ubantu 0
umeshw/ubantu 0
ca219y/ubantu 0
jbodake/ubantu 0
snowlove25/ubantu 0
anjanmaity/ubantuplusapache 0
licw81771061/ubantu_jdk7_tomcat7 0
amitgupta30/ubantu 0
dockerjqy89/ubantu_ueransim 0
damuvijji/ubantu_vim_curl 0
sunilajmera/ubantu 0
chintanmakdocker/ubantu 0
dockersameer1995/ubantu 0
wenruidocker/ubantu 0
$ docker search --filter is-official=true ubantu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
$ echo $?
0
官方仓库中没有官方镜像 ( Docker Official Images ),小白碰到这种情况如何处理呢???
其实,Docker Hub 中已经为你提供了很多关于 ubantu 的镜像,docker search ubantu
显示了所有关于 ubantu 的镜像。
到了这里,你肯定在好奇,为什么 NAME
中的仓库名会有 /
, 比如 boystar/ubantu
, 其实这里就是涉及 注册服务器(Docker Registry
)。
最常使用的 Docker Registry 公开服务是官方的 Docker Hub,这也是默认的 Registry,并拥有大量的高质量的镜像。
也就是说,你在 https://hub.docker.com
免费注册一个 Docker 账号longcs
。然后用该账号登陆并创建一个自己的仓库:longcs6
此时在Docker Hub中你的仓库名为 longcs/longcs6
(两段式名称)
注册服务器是管理仓库(Repository
)的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像。从这方面来说,仓库可以被认为是一个具体的项目或目录。例如对于仓库地址 docker.io/boystar/ubuntu
来说,docker.io
是注册服务器地址,boystar/ubuntu
是仓库名。
可以看到docker search ubantu
返回了很多包含关键字ubantu
的镜像,其中包括镜像名字、描述、收藏数(表示该镜像的受关注程度)、是否官方创建(OFFICIAL
)、是否自动构建 (AUTOMATED
)。
根据是否是官方提供,可将镜像分为两类。
一种是类似 ubantu
这样的镜像,被称为基础镜像或根镜像。这些基础镜像由 Docker 公司创建、验证、支持、提供。这样的镜像往往使用单个单词作为名字。
还有一种类型,比如 boystar/ubantu
镜像,它是由 Docker Hub 的注册用户创建并维护的,往往带有用户名称前缀。可以通过前缀 username/
来指定使用某个用户提供的镜像,比如 boystar 用户。
$ docker pull boystar/ubantu
Using default tag: latest
latest: Pulling from boystar/ubantu
a64038a0eeaa: Pull complete
2ec6e7edf8a8: Pull complete
0a5fb6c3c94b: Pull complete
a3ed95caeb02: Pull complete
f041f6070966: Pull complete
7e8b555bd6ba: Pull complete
Digest: sha256:476636fc1bedc7bca792f97e8e14e66257d02f3535f5a627390999ffd0b75b4e
Status: Downloaded newer image for boystar/ubantu:latest
docker.io/boystar/ubantu:latest
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you dont have a Docker ID, head over to https://hub.docker.com to create one.
Username: longcs
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker pull longcs/longcs6
Using default tag: latest
Error response from daemon: manifest for longcs/longcs6:latest not found: manifest unknown: manifest unknown
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 46331d942d63 8 months ago 9.14kB
boystar/ubantu latest e69d4e2b6757 5 years ago 237MB
$ docker tag boystar/ubantu longcs/longcs6:Linux1
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 46331d942d63 8 months ago 9.14kB
boystar/ubantu latest e69d4e2b6757 5 years ago 237MB
longcs/longcs6 Linux1 e69d4e2b6757 5 years ago 237MB
$ docker push longcs/longcs6:Linux1
The push refers to repository [docker.io/longcs/longcs6]
0a008ebd5322: Mounted from boystar/ubantu
066c8e6bfd53: Mounted from boystar/ubantu
5f70bf18a086: Mounted from boystar/ubantu
6f32b23ac95d: Mounted from boystar/ubantu
14d918629d81: Mounted from boystar/ubantu
fd0e26195ab2: Mounted from boystar/ubantu
Linux1: digest: sha256:476636fc1bedc7bca792f97e8e14e66257d02f3535f5a627390999ffd0b75b4e size: 1574
$ docker search longcs6
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
longcs/longcs6 0
$ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos DEPRECATED; The official build of CentOS. 7417 [OK]
kasmweb/centos-7-desktop CentOS 7 desktop for Kasm Workspaces 26
couchbase/centos7-systemd centos7-systemd images with additional debug… 5 [OK]
dokken/centos-7 CentOS 7 image for kitchen-dokken 4
dokken/centos-stream-8 3
continuumio/centos5_gcc5_base 3
dokken/centos-stream-9 2
dokken/centos-8 CentOS 8 image for kitchen-dokken 2
spack/centos7 CentOS 7 with Spack preinstalled 1
spack/centos6 CentOS 6 with Spack preinstalled 1
ustclug/centos Official CentOS Image with USTC Mirror 0
dokken/centos-6 CentOS 6 image for kitchen-dokken 0
datadog/centos-i386 0
bitnami/centos-extras-base 0
couchbase/centos-72-java-sdk 0
corpusops/centos-bare https://github.com/corpusops/docker-images/ 0
couchbase/centos-72-jenkins-core 0
corpusops/centos centos corpusops baseimage 0
couchbase/centos-70-sdk-build 0
couchbase/centos-69-sdk-build 0
couchbase/centos-69-sdk-nodevtoolset-build 0
bitnami/centos-base-buildpack Centos base compilation image 0 [OK]
fnndsc/centos-python3 Source for a slim Centos-based Python3 image… 0 [OK]
spack/centos-stream 0
dokken/centos-5 EOL DISTRO: For use with kitchen-dokken, Bas… 0
$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
52f9ef134af7: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest