1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker Registryを自前で構築する

Last updated at Posted at 2023-05-28

はじめに

開発用コンテナ等をDockerHubにpushしていくと、どんどん汚れていくし、セキュリティ的にも良くない。
そこで今回は、開発用コンテナをローカルのレジストリで管理するために、Docker Registryを構築する。

構築

docker-compsoe.yml

version: '3.3'
services:
    registry:
        ports:
            - '5000:5000'
        container_name: registry
        image: 'registry:latest'

起動

docker-compose up

起動確認

CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS          PORTS                                       NAMES
68ee52f8a4d0   registry:latest    "/entrypoint.sh /etc…"   24 minutes ago   Up 24 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry

registryの使用

Dockerイメージのビルド

docker build ./web -t shomaigu/skillsfolio:0.1 .

DockerイメージのPush

docker tag shomaigu/skillsfolio:0.1 localhost:5000/shomaigu/skillsfolio:0.1
docker push localhost:5000/shomaigu/skillsfolio:0.1

registryの挙動確認

localイメージの削除

docker rmi localhost:5000/shomaigu/skillsfolio:0.1 --force

レジストリからPullして動かす

docker pull localhost:5000/shomaigu/skillsfolio:0.1
docker run localhost:5000/shomaigu/skillsfolio:0.1

registryの中身の確認方法

curl http://localhost:5000/v2/_catalog

webダッシュボードを構築する

いちいちcurlなんか叩いてられないよ!という方向けにwebダッシュボードを構築する。

docker-compose.yml

version: '3.3'
services:
    docker-registry-frontend:
        environment:
            - ENV_DOCKER_REGISTRY_HOST=registry(registryのコンテナ名)
            - ENV_DOCKER_REGISTRY_PORT=5000
        ports:
            - '8080:80'
        image: 'konradkleine/docker-registry-frontend:v2'

アクセス

image.png
image.png

Dockerregistryの永続化

docker-composeをdownすると、registryの中身はなくなってしまう。そこで、registryの永続化を行いましょう。

        volumes:
          - ./vol:/var/lib/registry

完成形

docker-compose.yml

version: '3.3'
services:
    registry:
        ports:
            - '5000:5000'
        container_name: registry
        image: 'registry:latest'
        volumes:
            - './certs:/certs'
            - './vol:/var/lib/registry'
#        environment:
#            - REGISTRY_HTTP_TLS_CERTIFICATE=/certs/shoma.crt
#            - REGISTRY_HTTP_TLS_KEY=/certs/shoma.key


    docker-registry-frontend:
        container_name: docker-registry-frontend
        hostname: docker-registry-frontend
        environment:
            - ENV_DOCKER_REGISTRY_HOST=registry
            - ENV_DOCKER_REGISTRY_PORT=5000
        ports:
            - '8080:80'
        image: 'konradkleine/docker-registry-frontend:v2'
参考文献

https://genzouw.com/entry/2021/06/14/072906/2656/
https://qiita.com/Brutus/items/da63d23be32d505409c6#%E4%BB%96%E3%81%AEdocker%E3%82%AF%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%83%88%E3%81%8B%E3%82%89%E3%81%AE%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?