Docker之仓库的使用

  • A+
所属分类:Docker  虚拟化/私有云
摘要

仓库顾名思义是一个集中存放镜像的地方。
docker的仓库分公共仓库和私有仓库,一般我们默认用的搜索镜像都是在公共仓库中进行的搜索。本文就来说说docker的仓库。

一、Docker Hub的使用

Docker Hub是Docker官方维护的仓库,里面已经包含了很多的镜像,一般我们的需求直接在官方仓库搜索就可以得到解决。在官方的公共仓库中我们无需登录就可以进行镜像的搜索和下载。

docker search命令进行搜索

docker pull命令进行下载

搜索镜像命令详细用法: docker search [OPTIONS] TERM

  --automated=false    Only show automated builds
  --help=false         Print usage
  --no-trunc=false     Don't truncate output
  -s, --stars=0        Only displays with at least x stars
[root@docker-node1 ~]# docker search mariadb
NAME                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mariadb                                   MariaDB is a community-developed fork of M...   297       [OK]       
paintedfox/mariadb                        A docker image for running MariaDB 5.5, a ...   28                   [OK]
bitnami/mariadb                           Bitnami MariaDB Docker Image                    8                    [OK]
million12/mariadb                         MariaDB 10 on CentOS-7 with UTF8 defaults       6                    [OK]
maxexcloo/mariadb                         Docker service container with MariaDB inst...   4                    [OK]
diegomarangoni/mariadb-galera             Creates a MariaDB Galera Cluster                4                    [OK]
dylanlindgren/docker-mariadb              Docker image for MariaDB                        4                    [OK]
tianon/mariadb                            ♪ "I just met a girl named Maria!" ♫            4                    [OK]
kakilangit/mariadb                        Docker for MariaDB with OQGraph & TokuDB E...   2                    [OK]
kalabox/mariadb                                                                           1                    [OK]
desertbit/mariadb                         This is an extended docker image of the of...   1                    [OK]
arccoza/mariadb                           A simple, flexible Docker image for MariaD...   1                    [OK]
russmckendrick/mariadb                    A MariaDB image                                 1                    [OK]
dperson/mariadb                                                                           1                    [OK]
hauptmedia/mariadb                                                                        1                    [OK]
wodby/mariadb                                                                             0                    [OK]
pagafa/mariadb                            Alpine Linux 3.2 with mariadb                   0                    [OK]
projectatomic/mariadb-centos7-atomicapp   MariaDB Atomic App                              0                    [OK]
dasrick/fedora-mariadb                    MariaDB image - port 3306 - based on Fedora20   0                    [OK]
webhippie/mariadb                         Docker images for mariadb                       0                    [OK]
nimmis/mariadb                            MariaDB multiple versions based on nimmis/...   0                    [OK]
mmckeen/mariadb                           MariaDB image based on openSUSE Tumbleweed      0                    [OK]
phase2/mariadb                            MariaDB container for MySQL based builds        0                    [OK]
greencape/mariadb                         This image provides MariaDB.                    0                    [OK]
bitergia/mariadb                          MariaDB Docker image                            0                    [OK]
[root@docker-node1 ~]# docker pull mariadb
Using default tag: latest
latest: Pulling from library/mariadb
bff2a7d23e6a: Pull complete 
563338c072d0: Pull complete 
2830964fcb7b: Pull complete 
0a530faf98b1: Pull complete 
c49667d4141f: Pull complete 
59d03201d345: Pull complete 
f4b68fec540e: Pull complete 
b4ba6faf7dca: Pull complete 
2873a07bfccd: Pull complete 
d6ebf4bf73cf: Pull complete 
2015e3fa0aaf: Pull complete 
cebe446251c0: Pull complete 
a30be568bf4c: Pull complete 
Digest: sha256:73693ccfb1477b1989968f7651cbc7efc837a74d206077b0aea6d396c09f06e7
Status: Downloaded newer image for mariadb:latest
[root@docker-node1 ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
mariadb             latest              a30be568bf4c        4 days ago          302.1 MB
ubuntu              14.04               e9ae3c220b23        5 days ago          187.9 MB
debian              latest              91bac885982d        5 days ago          125.1 MB
centos              6.7                 7e8fbd86f46d        4 weeks ago         190.6 MB
[root@docker-node1 ~]# 
[root@docker-node1 ~]# docker search mariadb|head -3
NAME                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mariadb                                   MariaDB is a community-developed fork of M...   297       [OK]       
paintedfox/mariadb                        A docker image for running MariaDB 5.5, a ...   28                   [OK]
[root@docker-node1 ~]# docker search centos|head -3
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                              The official build of CentOS.                   1604      [OK]       
jdeathe/centos-ssh                  CentOS-6 6.6 x86_64 / EPEL/IUS Repos / Ope...   10                   [OK]
[root@docker-node1 ~]# docker search nginx|head -3
NAME                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                     Official build of Nginx.                        1658      [OK]       
jwilder/nginx-proxy       Automated Nginx reverse proxy for docker c...   403                  [OK]
[root@docker-node1 ~]# docker search ubuntu|head -3
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                         Ubuntu is a Debian-based Linux operating s...   2631      [OK]       
ubuntu-upstart                 Upstart is an event-based replacement for ...   42        [OK]       
[root@docker-node1 ~]# 

通过上面的几个搜索大家可能能发现有些镜像名字就是一些系统或者程序的名字,这些镜像都是有Docker公司创建、验证、支持、提供的。

[root@docker-node1 ~]# docker search -s 100 ubuntu|head -3
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu    Ubuntu is a Debian-based Linux operating s...   2631      [OK]       
[root@docker-node1 ~]# docker search -s 100 ubuntu
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu    Ubuntu is a Debian-based Linux operating s...   2631      [OK]       
[root@docker-node1 ~]# docker search -s 100 mariadb
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mariadb   MariaDB is a community-developed fork of M...   297       [OK]       
[root@docker-node1 ~]# docker search -s 100 mysql
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relati...   1319      [OK]       
[root@docker-node1 ~]# 

通过上面可以发现我们在搜索的时候可以加-s参数来指定搜索星数大于多少的镜像。

Ⅰ、帐号注册

docker的官方公共仓库我们可以非常简单的就进行注册使用,地址 https://hub.docker.com/

Ⅱ、登录

执行docker login就可以进行登录操作。

[root@docker-node1 ~]# docker login 
Username: benyoo
Password: 
Email: m*********@gmail.com
WARNING: login credentials saved in /root/.docker/config.json
Login Succeeded
[root@docker-node1 ~]# cat ~/.docker/config.json 
{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "YmVueW9vOnRhb3hpYW95dTE5ODg=",
            "email": "m*********@gmail.com"
        }
    }
}[root@docker-node1 ~]# 

Docker之仓库的使用

二、创建私有仓库

我们可以使用官方的registry镜像创建一个本地的私有仓库。

[root@docker-node1 ~]# docker search -s 100 registry
NAME       DESCRIPTION                     STARS     OFFICIAL   AUTOMATED
registry   Containerized docker registry   482       [OK]       
[root@docker-node1 ~]# docker run -d -p 5000:5000 -v /docker/registry:/tmp/registry registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
76efbda47e08: Pull complete 
73bf53db741c: Pull complete 
4c829a32d6df: Pull complete 
99730d8bbd0b: Pull complete 
f19a0609fffe: Pull complete 
7f7baa145866: Pull complete 
75223bf2060b: Pull complete 
b8920c5da9b4: Pull complete 
8b6906266e10: Pull complete 
1cb234ccb22b: Pull complete 
Digest: sha256:3ccf94a100df947453d1f33b739f80323c5a9c25dcc03b7c87e78a845a7cbeda
Status: Downloaded newer image for registry:latest
9128b4a3d332e20270d4ea86c62d3167753e8af3c0e74d3b66b29b6ee354e115
[root@docker-node1 ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry            latest              1cb234ccb22b        4 days ago          422.8 MB
mariadb             latest              a30be568bf4c        4 days ago          302.1 MB
ubuntu              14.04               e9ae3c220b23        5 days ago          187.9 MB
debian              latest              91bac885982d        5 days ago          125.1 MB
centos              6.7                 7e8fbd86f46d        4 weeks ago         190.6 MB
[root@docker-node1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
9128b4a3d332        registry            "docker-registry"   11 seconds ago      Up 10 seconds       0.0.0.0:5000->5000/tcp   big_fermat
[root@docker-node1 ~]# ss -tnl |grep 5000
LISTEN     0      128                      :::5000                      :::*     
[root@docker-node1 ~]# 

命令解释:默认情况下私有仓库的网络是监听在5000端口上的这里我们用-p命令指定宿主机上5000给镜像的5000端口,
默认情况仓库是容器是创建在/tmp/registry目录下这里我们用-v参数来指定了路径

三、管理私有仓库镜像

[root@docker-node1 ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry            latest              1cb234ccb22b        4 days ago          422.8 MB
mariadb             latest              a30be568bf4c        4 days ago          302.1 MB
ubuntu              14.04               e9ae3c220b23        5 days ago          187.9 MB
debian              latest              91bac885982d        5 days ago          125.1 MB
centos              6.7                 7e8fbd86f46d        4 weeks ago         190.6 MB
[root@docker-node1 ~]# 

通过上面我们可以看到我们本机上已经有了不少个镜像,现在我们来试试将本机上的镜像上传到我们自己的私有仓库中

[root@docker-node1 ~]# docker tag mariadb:latest 127.0.0.1:5000/mariadb
[root@docker-node1 ~]# docker images 
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry                 latest              1cb234ccb22b        4 days ago          422.8 MB
127.0.0.1:5000/mariadb   latest              a30be568bf4c        4 days ago          302.1 MB
mariadb                  latest              a30be568bf4c        4 days ago          302.1 MB
ubuntu                   14.04               e9ae3c220b23        5 days ago          187.9 MB
debian                   latest              91bac885982d        5 days ago          125.1 MB
centos                   6.7                 7e8fbd86f46d        4 weeks ago         190.6 MB
[root@docker-node1 ~]# 
[root@docker-node1 ~]# docker push 127.0.0.1:5000/mariadb
The push refers to a repository [127.0.0.1:5000/mariadb] (len: 1)
Sending image list
Pushing repository 127.0.0.1:5000/mariadb (1 tags)
a719479f5894: Image successfully pushed 
91bac885982d: Image successfully pushed 
bff2a7d23e6a: Image successfully pushed 
563338c072d0: Image successfully pushed 
2830964fcb7b: Image successfully pushed 
0a530faf98b1: Image successfully pushed 
c49667d4141f: Image successfully pushed 
59d03201d345: Image successfully pushed 
f4b68fec540e: Image successfully pushed 
b4ba6faf7dca: Image successfully pushed 
2873a07bfccd: Image successfully pushed 
d6ebf4bf73cf: Image successfully pushed 
2015e3fa0aaf: Image successfully pushed 
cebe446251c0: Image successfully pushed 
a30be568bf4c: Image successfully pushed 
Pushing tag for rev [a30be568bf4c] on {http://127.0.0.1:5000/v1/repositories/mariadb/tags/latest}
[root@docker-node1 ~]# 
lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: