Gitlab 简明教程
GitLab CI - Container Registry
Description
容器注册表是一个存储和内容交付系统,用于存储其 Docker(它是用于运行应用程序的预定义映像的数据库。)映像。
Container registry is a storage and content delivery system, which stores their Docker (it is database of predefined images used to run applications.) images.
Deploying the Registry
您可以使用以下命令部署注册表 −
You can deploy the registry by using the below commands −
Step 1 − 首先,使用 SSH(安全外壳)登录到你的 GitLab 服务器。
Step 1 − First, login to your GitLab server using SSH (Secure Shell).
Step 2 − 现在,使用以下命令启动注册表容器 −
Step 2 − Now start the registry container by using below command −
$ docker run -d -p 5000:5000 --restart = always --name registry registry:2

-p 5000:5000 将第一部分指定为主机端口,将第二部分指定为容器中的端口。--restart = always 为 Docker 重新启动时,自动重新启动注册表。registry:2 被定义为一个映像。
The -p 5000:5000 specifies first part as host port and second part as port within the container. The --restart = always flag restarts the registry automatically when Docker restarts. The registry:2 is defined as an image.
Step 3 − 现在,将映像从 Docker Hub 拉取到您的注册表 −
Step 3 − Now, pull the image from Docker hub to your registry −
$ docker pull ubuntu:16.04

上述命令从 Docker Hub 拉取 ubuntu:16.04 映像。
The above command pulls the ubuntu:16.04 image from Docker Hub.
Step 4 − 接下来,标记映像以指向您的注册表 −
Step 4 − Next, tag the image to point your registry −
$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu
在这里,我们在为现有的 ubuntu:16.04 映像标记 localhost:5000/my-ubuntu 映像。
Here, we are tagging the localhost:5000/my-ubuntu image for an existing ubuntu:16.04 image.
Step 5 − 将映像推送到在 localhost:5000 处执行的本地注册表。
Step 5 − Push the image to local registry which is executing at localhost:5000.
$ docker push localhost:5000/my-ubuntu

Step 6 − 现在,从注册表中删除缓存映像(ubuntu:16.04 和 localhost:5000/my-ubuntu) −
Step 6 − Now remove the cached (ubuntu:16.04 and localhost:5000/my-ubuntu) images from the registry −
$ docker image remove ubuntu:16.04
$ docker image remove localhost:5000/my-ubuntu

Step 7 − 从本地注册表中拉回 localhost:5000/my-ubuntu 映像 −
Step 7 − Pull back the localhost:5000/my-ubuntu image from local registry −
$ docker pull localhost:5000/my-ubuntu

Step 8 − 现在停止注册表并删除数据 −
Step 8 − Now stop the registry and remove the data −
$ docker container stop registry && docker container rm -v registry
