Docker 仓库管理
仓库(Repository)是集中存放镜像的地方。以下介绍一下 Docker Hub。当然不止 docker hub,只是远程的服务商不一样,操作都是一样的。
Docker Hub
目前 Docker 官方维护了一个公共仓库 dDocker Hub。
大部分需求都可以通过在 Docker Hub 中直接下载镜像来实现。
注册
在Docker Hub免费注册一个 Docker 账号
登录、退出、使用
登录需要输入用户名和密码,登录成功后,我们就可以从 docker hub 上拉取自己账号下的全部镜像。
- 登录
[root@localhost ~]#: docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 270330615
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
- 退出
[root@localhost ~]#: docker logout
Removing login credentials for https://index.docker.io/v1/
- 拉取镜像
你可以通过 docker search 命令来查找官方仓库中的镜像,并利用 docker pull 命令来将它下载到本地。
以 ubuntu 为关键词进行搜索:
[root@localhost ~]#: docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 10167 [OK]
dorowu/ubuntu-desktop-lxde-vnc Docker image to provide HTML5 VNC interface … 362 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 235 [OK]
- 镜像下载
使用 docker pull 将官方 ubuntu 镜像下载到本地:
[root@localhost ~]#: docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest
- 推送镜像
用户登录后,可以通过 docker push 命令将自己的镜像推送到 Docker Hub。
以下命令中的 username 请替换为你的 Docker 账号用户名。
[root@localhost ~]#: docker tag ubuntu 270330615/ubuntu
[root@localhost ~]#: docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
270330615/ubuntu latest 775349758637 2 weeks ago 64.2MB
[root@localhost ~]#: docker push username/ubuntu:18.04
[root@localhost ~]#: docker search username/ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
username/ubuntu
转载至:https://www.runoob.com/docker/docker-repository.html