Docker笔记6 | 关于仓库的一些基本知识梳理
  NHjqxS4aAIAZ 2023年11月02日 18 0

(6 | 关于仓库的一些基本知识梳理)

1 Docker Hub

1.1 简介和登陆

在这里插入图片描述

  • 注册账号以后可以使用docker login进行登陆:

在这里插入图片描述 在这里插入图片描述

  • 使用docker logout进行退出。 在这里插入图片描述

1.2 拉取镜像

  • 使用docker search查找镜像;
noamanelson@noamanelson-Virtual-Machine:~$ docker search ubuntu
NAME                             DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
ubuntu                           Ubuntu is a Debian-based Linux operating sys…   15954     [OK]       
websphere-liberty                WebSphere Liberty multi-architecture images …   294       [OK]       
open-liberty                     Open Liberty multi-architecture images based…   59        [OK]       
neurodebian                      NeuroDebian provides neuroscience research s…   99        [OK]       
ubuntu-debootstrap               DEPRECATED; use "ubuntu" instead                 51        [OK]       
ubuntu-upstart                   DEPRECATED, as is Upstart (find other proces…   114       [OK]       
ubuntu/nginx                     Nginx, a high-performance reverse proxy & we…   91                   
ubuntu/cortex                    Cortex provides storage for Prometheus. Long…   3                    
ubuntu/squid                     Squid is a caching proxy for the Web. Long-t…   57                   
ubuntu/apache2                   Apache, a secure & extensible open-source HT…   58                   
ubuntu/mysql                     MySQL open source fast, stable, multi-thread…   48                   
ubuntu/kafka                     Apache Kafka, a distributed event streaming …   31                   
ubuntu/bind9                     BIND 9 is a very flexible, full-featured DNS…   51                   
ubuntu/redis                     Redis, an open source key-value store. Long-…   18                   
ubuntu/prometheus                Prometheus is a systems and service monitori…   40                   
ubuntu/postgres                  PostgreSQL is an open source object-relation…   27                   
ubuntu/zookeeper                 ZooKeeper maintains configuration informatio…   5                    
ubuntu/grafana                   Grafana, a feature rich metrics dashboard & …   9                    
ubuntu/memcached                 Memcached, in-memory keyvalue store for smal…   5                    
ubuntu/prometheus-alertmanager   Alertmanager handles client alerts from Prom…   8                    
ubuntu/dotnet-deps               Chiselled Ubuntu for self-contained .NET & A…   8                    
ubuntu/dotnet-runtime            Chiselled Ubuntu runtime image for .NET apps…   5                    
ubuntu/dotnet-aspnet             Chiselled Ubuntu runtime image for ASP.NET a…   6                    
ubuntu/cassandra                 Cassandra, an open source NoSQL distributed …   2                    
ubuntu/telegraf                  Telegraf collects, processes, aggregates & w…   4  
  • 查找到有很多镜像,基本分为两类:一类是官方创建的,比如OFFICIAL下标识是OK的;另一类是由由 Docker Hub 的注册用户创建并维护的,往往带有用户名称前缀。
  • 使用docker pull将镜像拉取到本地,比如拉取官方的ubuntu在这里插入图片描述

1.3 推送镜像

  • 命令为:docker push,将自己的镜像推送到Docker Hub在这里插入图片描述
  • 登陆后使用docker search 用户名查找用户下的镜像:

在这里插入图片描述

1.4 自动构建

  • 使用场景为:

构建了镜像,安装了某个软件,当软件发布新版本则需要手动更新镜像。

  • 说明:

自动构建允许用户通过 Docker Hub 指定跟踪一个目标网站(支持 GitHub 或 BitBucket)上的项目,一旦项目发生新的提交 (commit)或者创建了新的标签(tag),Docker Hub 会自动构建镜像并推送到 Docker Hub中。

  • 操作步骤:

1、登录 Docker Hub; 在这里插入图片描述

2、在 Docker Hub 点击右上角头像,在账号设置(Account Settings)中关联(Linked Accounts)目标网站; 在这里插入图片描述

3、在 Docker Hub 中新建或选择已有的仓库,在 Builds 选项卡中选择Configure Automated Builds ; 4、选取一个目标网站中的项目(需要含 Dockerfile )和分支;指定 Dockerfile 的位置,并保存。

2 私有仓库

2.1 简介

  • 可以创建本地仓库供私人使用;
  • docker-registry 是官方提供的工具,可以用于构建私有的镜像仓库

2.2 安装docker-registry

  • 命令:
docker run -d -p 5000:5000 --restart=always --name registry registry

说明: 1、使用官方的 registry 镜像来启动私有仓库; 2、默认情况,仓库会被创建在容器的/var/lib/registry 目录下; 3、使用-v参数修改默认地址: docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry 在这里插入图片描述

2.3 上传镜像

  • 使用 docker tag 来标记一个镜像,然后推送它到仓库;
  • 比如将使用 docker tagubuntu:latest 这个镜像标记为 localhost/ubuntu:latest

在这里插入图片描述

  • 使用docker push上传:
noamanelson@noamanelson-Virtual-Machine:~$ docker image rm 127.0.0.1:5000/ubuntu:latest 
Error response from daemon: No such image: 127.0.0.1:5000/ubuntu:latest
noamanelson@noamanelson-Virtual-Machine:~$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
noamanelson@noamanelson-Virtual-Machine:~$ docker image ls
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
registry                latest    65f3b3441f04   4 days ago      24MB
127.0.0.1:5000/ubuntu   latest    3b418d7b466a   2 weeks ago     77.8MB
ubuntu                  latest    3b418d7b466a   2 weeks ago     77.8MB
ubuntu                  18.04     3941d3b032a8   2 months ago    63.1MB
hello-world             latest    feb5d9fea6a5   19 months ago   13.3kB
noamanelson@noamanelson-Virtual-Machine:~$ docker push 127.0.0.1:5000/ubuntu:latest
The push refers to repository [127.0.0.1:5000/ubuntu]
b8a36d10656a: Pushed 
latest: digest: sha256:8d741c3fb719fff7991700dbe988d1d549f32b3c24ae2276657f4a4ca0fbe42d size: 529
noamanelson@noamanelson-Virtual-Machine:~$ 

2.4 查看镜像

  • 使用curl查看仓库中的镜像:
noamanelson@noamanelson-Virtual-Machine:~$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["ubuntu"]}

2.5 下载镜像

  • 删除这个镜像: 在这里插入图片描述
  • 使用docker pull下载: 在这里插入图片描述
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  eRzqeykGhyfD   2023年11月02日   21   0   0 Ubuntu
  uRXtDv0LQww7   2023年12月09日   15   0   0 Ubuntu
  cpKFwc6sMdmP   2023年11月02日   48   0   0 UbuntuPHPapache
NHjqxS4aAIAZ
最新推荐 更多