self-host a private Docker registry

embedded/2024/11/23 18:14:07/

You can create a private Docker registry to serve as your own “Docker Hub” for internal use, which can be cost-effective and give you full control over your images. Setting up a self-hosted Docker registry is straightforward and can be hosted on your own infrastructure, on-premises servers, or even your private cloud. Here’s how you can do it:


1. Use Docker’s Official Registry Image

Docker provides an official image to set up your private registry.

Steps:
  1. Run the Registry Container:

    docker run -d -p 5000:5000 --name registry --restart=always registry:2
    

    This starts a registry on port 5000.

  2. Test the Registry:

    • Tag a local image:
      docker tag your-image localhost:5000/your-image
      
    • Push the image:
      docker push localhost:5000/your-image
      
    • Pull the image:
      docker pull localhost:5000/your-image
      
  3. Persist Data:
    By default, data is not persistent. Use a volume to store images:

    docker run -d -p 5000:5000 --name registry --restart=always -v /path/to/registry/data:/var/lib/registry registry:2
    

2. Secure the Registry with HTTPS

To use the registry in a production environment, secure it with HTTPS.

Steps:
  1. Generate SSL Certificates:
    Use a trusted certificate or generate a self-signed certificate:

    openssl req -newkey rsa:4096 -nodes -sha256 -keyout domain.key -x509 -days 365 -out domain.crt
    
  2. Configure Docker Registry with HTTPS:
    Mount the certificate and key to the container:

    docker run -d -p 443:5000 --name registry \--restart=always \-v /path/to/registry/data:/var/lib/registry \-v /path/to/domain.crt:/certs/domain.crt \-v /path/to/domain.key:/certs/domain.key \-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \registry:2
    
  3. Access Your Secure Registry:
    Use the registry with HTTPS:

    docker tag your-image your-domain.com/your-image
    docker push your-domain.com/your-image
    
  4. Handle Self-Signed Certificates:
    If using self-signed certificates, configure Docker clients to trust them:

    • Copy the .crt file to /etc/docker/certs.d/your-domain.com/ca.crt.

3. Use Authentication for Access Control

Add authentication to secure the registry further.

Steps:
  1. Create a Password File:
    Use htpasswd to create a password file:

    docker run --rm --entrypoint htpasswd registry:2 -Bbn username password > /path/to/auth/htpasswd
    
  2. Run the Registry with Authentication:
    Mount the password file and configure the registry:

    docker run -d -p 443:5000 --name registry \--restart=always \-v /path/to/registry/data:/var/lib/registry \-v /path/to/domain.crt:/certs/domain.crt \-v /path/to/domain.key:/certs/domain.key \-v /path/to/auth:/auth \-e REGISTRY_AUTH=htpasswd \-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" \-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \registry:2
    
  3. Access the Registry with Authentication:
    Log in to the registry before pushing/pulling images:

    docker login your-domain.com
    

4. Add a Frontend (Optional)

For large enterprises, providing a user-friendly interface can be beneficial. Consider using a registry frontend like:

  • Portus: An open-source Docker registry UI with user management.
    • GitHub: https://github.com/SUSE/Portus
  • Harbor: A cloud-native container registry with advanced features.
    • Official Site: https://goharbor.io/

5. Scale and High Availability (Optional)

For large enterprises, ensure the registry is scalable and resilient.

Options:
  1. Cluster Setup:
    Use tools like Kubernetes or Docker Swarm to manage multiple registry instances.

  2. Object Storage Backend:
    Configure the registry to use object storage (e.g., MinIO, AWS S3, Alibaba OSS) for scalability:

    • Update config.yml for the registry:
      storage:s3:accesskey: <your-access-key>secretkey: <your-secret-key>region: <region>bucket: <bucket-name>
      

By self-hosting a private Docker registry, you gain full control over your images, avoid cloud service fees, and comply with organizational policies. This approach is scalable and cost-effective for enterprises.


http://www.ppmy.cn/embedded/139251.html

相关文章

CentOS 升级 gcc 版本

CentOS 升级 gcc 版本 1. 安装步骤 CentOS7 默认的 gcc 版本是4.8&#xff0c;有时候需要更高版本&#xff0c;这里介绍一下如何将 gcc 版本升级到 8.3.1 安装 centos-release-scl yum install centos-release-scl安装devtoolset&#xff0c;注意&#xff0c;如果想安装 9.* …

Linux登录指令last详解

引言 在Linux系统中&#xff0c;了解用户登录记录是系统管理和安全审计的重要任务之一。last指令作为Linux系统中用于检索和展示用户登录信息的工具&#xff0c;扮演着至关重要的角色。本文将详细介绍last指令的定义、架构、原理、企业应用以及常见的命令体系&#xff0c;帮助…

Vue3 组件 view-shadcn-ui 2024.4.0 发布

View Shadcn UI 是一个基于 Tailwind CSS 构建的组件库。 推荐一套为 Java 开发人员提供方便易用的 SDK 来与目前提供服务的的 Open AI 进行交互组件&#xff1a;https://github.com/devlive-community/openai-java-sdk 推荐一套功能强大的开源数据中台系统&#xff1a;https:/…

k8s 中传递参数给docker容器

文章目录 docker启动时传递参数使用k8s env传递完全覆盖 ENTRYPOINT 和 CMD 在 Kubernetes 中&#xff0c;可以通过多种方式将参数传递给 Dockerfile 或其运行的容器&#xff0c;常见的方式包括使用环境变量、命令行参数、配置文件等。以下是一些常用的方法&#xff1a; docker…

国产三维CAD 2025新动向:推进MBD模式,联通企业设计-制造数据

本文为CAD芯智库原创整理&#xff0c;未经允许请勿复制、转载&#xff01; 上一篇文章阿芯分享了影响企业数字化转型的「MBD」是什么、对企业优化产品设计流程有何价值——这也是国产三维CAD软件中望3D 2024发布会上&#xff0c;胡其登先生&#xff08;中望软件产品规划与GTM中…

大三学生实习面试经历(1)

最近听了一位学长的建议&#xff0c;不能等一切都准备好再去开始&#xff0c;于是就开始了简历投递&#xff0c;恰好简历过了某小厂的初筛&#xff0c;开启了线上面试&#xff0c;记录了一些问题&#xff1a; &#xff08;通过面试也确实了解到了自己在某些方面确实做的还不够…

【Redis】Redis实现的消息队列

一、用list实现【这是数据类型所以支持持久化】 消息基于redis存储不会因为受jvm内存上限的限制&#xff0c;支持消息的有序性&#xff0c;基于redis的持久化机制&#xff0c;只支持单一消费者订阅&#xff0c;无法避免消息丢失。 二、用PubSub【这不是数据类型&#xff0c;是…

Spring、SpringMVC、SpringBoot、Mybatis小结

Spring Spring是一个轻量级的控制反转&#xff08;IoC&#xff09;和面向切面&#xff08;AOP&#xff09;的容器&#xff08;框架&#xff09; Spring框架的核心特性包括依赖注入&#xff08;Dependency Injection &#xff0c;DI&#xff09;、面向切面编程&#xff08;Aspe…