Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Setting Up a Private Docker Registry

This chapter from Docker Containers: Build and Deploy with Kubernetes, Flannel, Cockpit, and Atomic explains how to create a private Docker registry in Fedora or Ubuntu, use the docker-registry package, use the registry container image, and understand the Docker image namespace.
This chapter is from the book

One of the foundations of Docker is the ability to request to use an existing container image and then, if it is not already on your system, grab it from somewhere and download it to your system. By default, “somewhere” is the Docker Hub Registry (https://hub.docker.com). However, there are ways to configure other locations from which you can pull docker images. These locations are referred to as registries.

By setting up your own private registry, you can keep your private images to yourself. You can also save time by pushing and pulling your images locally, instead of having them go out over the Internet.

Setting up a private registry is simple. It requires getting the service (by installing a package or using the registry Docker container image), starting the service, and making sure the proper port is open so the service is accessible. Using registries requires a bit more explanation than setting up one, especially when you consider that features are added to Docker every day that are changing how Docker uses and searches registries for images.

In particular, the way that Docker uses the image namespace is changing to be more adaptable. If your location is disconnected from the Internet, with the Docker hub inaccessible, features are being developed to allow you to use a different default registry. Likewise, new features let you add registries to your search order, much the same way you can have an Internet browser look at different DNS servers.

This chapter describes how to set up a private Docker registry on several different Linux systems. The first examples are simply to help you get a Docker registry up and running quickly to begin testing or learning how to use registries. After that, I describe some techniques for making a Docker registry more production ready.

Later in the chapter, I tell you how to adapt the way your local Docker service uses Docker registries, including how to replace Docker.io as the default registry and add other registries to the search path.

Getting and Starting a Private Docker Registry

You can run a Docker registry on your Linux system in a number of different ways to store your own Docker images. For Linux distributions that include a docker-registry package (such as Fedora and Red Hat Enterprise Linux), you can install that package and start up the service. For other distributions, you can run the official registry container image from Docker.io to provide the service.

See the section later in the chapter that corresponds to the Linux system you are using for instructions on installing and running a Docker registry on that system. For Fedora, I illustrate how to use the docker-registry package, while for Ubuntu I show how to use the registry container.

Here are a few general things you should know about setting up a Docker registry:

  • Install anywhere: Like most servers, the Docker registry does not need to be installed on client systems (that is, where you run your docker commands). You can install it on any Linux system that your clients can reach over a network. That way, multiple Docker clients can access your Docker registry.
  • Open port: If your Docker registry is not on the client, you must be sure that TCP port 5000 is not being blocked by the firewall where the Docker registry is running.
  • Provide space: If you push a lot of images to your registry, space can fill up quickly. For the docker-registry package, stored images are contained in the /var/lib/docker-registry directory. Make sure you configure enough space in that directory to meet your needs, or you can configure a different directory, if you want.

Setting Up a Docker Registry in Fedora

Follow these instructions to install and start up a Docker registry on a Fedora system. At the moment, this procedure creates a version 1 Docker registry from the docker-registry RPM package. Although this procedure was tested on Fedora, the same basic procedures should work for the following Linux distributions:

  • Fedora 22 or later
  • Red Hat Enterprise Linux 7.1 or later
  • CentOS 7.1 or later

The docker-registry package is not included in the Atomic project Fedora, RHEL, and CentOS distributions. So you must use the registry container, described later for setting up a Docker registry in Ubuntu, to get that feature on an Atomic Linux system.

  1. Install docker-registry: When you install the docker-registry package in Fedora, it pulls in more than a dozen dependent packages as well. To install those packages, type the following:

    # yum install docker-registry
    ...
    Transaction Summary
    ============================================
    Install  1 Package (+15 Dependent packages)
    Total download size: 6.8 M
    Installed size: 39 M
    Is this ok [y/d/N]: y
  2. List docker-registry contents: Use the rpm command to list the contents of the docker-registry file in Fedora. There are nearly 200 files (mostly python code in the package). This command shows you only documentation and configuration files (I describe how to configure them later):

    # rpm -ql docker-registry | grep -E "(/etc)|(/usr/share)|(systemd)"
    /etc/docker-registry.yml
    /etc/sysconfig/docker-registry
    /usr/lib/systemd/system/docker-registry.service
    /usr/share/doc/docker-registry
    /usr/share/doc/docker-registry/AUTHORS
    /usr/share/doc/docker-registry/CHANGELOG.md
    /usr/share/doc/docker-registry/LICENSE
    /usr/share/doc/docker-registry/README.md
  3. Open firewall: If your Fedora system is running a firewall that blocks incoming connections, you may need to open TCP port 5000 to allow access to the Docker registry service. Assuming you are using the firewall service in Fedora, run these commands to open the port on the firewall (immediately and permanently) and see that the port has been opened:

    # firewall-cmd --zone=public --add-port=5000/tcp
    # firewall-cmd --zone=public --add-port=5000/tcp --permanent
    # firewall-cmd --zone=public --list-ports
    5000/tcp
  4. Start the docker-registry service: If you want to do any special configuration for your Docker registry, refer to the next sections before starting the service. For a simple docker-registry installation, however, you can simply start the service and begin using it, as follows (as the status shows, the docker-registry service is active and enabled):

    # systemctl start docker-registry
    # systemctl enable docker-registry
    Created symlink from
      /etc/systemd/system/multi-user.target.wants/docker-registry.
    service
      to /usr/lib/systemd/system/docker-registry.service.
    # systemctl status docker-registry
    docker-registry.service - Registry server for Docker
     Loaded: loaded (/usr/lib/systemd/system/docker-registry.
    service;enabled)
     Active: active (running) since Mon 2015-05-25 12:02:14 EDT; 42s ago
    Main PID: 5728 (gunicorn)
       CGroup: /system.slice/docker-registry.service
           boxvr.jpg5728 /usr/bin/python /usr/bin/gunicorn --access-logfile
                - --max-requests 100 --graceful-timeout 3600-t 36...
    ...
  5. Get an image: A common image used to test Docker is the hello-world image available from the Docker Hub Registry. Run that image as follows (which pulls that image to the local system and runs it):

    # docker run --name myhello hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from docker.io/hello-world
    91c95931e552: Download complete
    a8219747be10: Download complete
    Hello from Docker.
    docker.io/hello-world:latest: The image you are pulling has been
    verified.
    ...
  6. Allow access to registry: The docker clients in Fedora and Red Hat Enterprise Linux require that you either obtain a certificate from the registry or you identify the registry as insecure. For this example, you can identify the registry as insecure by editing the /etc/sysconfig/docker file and creating the following lines in that file:

    ADD_REGISTRY='--add-registry localhost:5000'
    INSECURE_REGISTRY='--insecure-registry localhost:5000'

    After that, restart the local Docker service:

    # systemctl restart docker
  7. Tag the image: Use docker tag to give the image a name that you can use to push it to the Docker registry on the local system:

    # docker tag hello-world localhost:5000/hello-me:latest
  8. Push the image: To push the hello-world to the local Docker registry, type the following:

    # docker push localhost:5000/hello-me:latest
    The push refers to a repository [localhost:5000/hello-me] (1 tags)
    ...
    Pushing tag for rev [91c95931e552] on
         {http://localhost:5000/v1/repositories/hello-me/tags/latest}
  9. Pull the image: To make sure you can retrieve the image from the registry, in the second Terminal, remove the image from your system, then try to retrieve it from your local registry:

    # docker rm myhello
    # docker rmi hello-world localhost:5000/hello-me:latest
    # docker pull localhost:5000/hello-me:latest
    Pulling repository localhost:5000/hello-me
    91c95931e552: Download complete
    a8219747be10: Download complete
    # docker images
    REPOSITORY              TAG    IMAGE ID     CREATED     VIRTUAL SIZE
    localhost:5000/hello-me latest 91c95931e552 5 weeks ago 910 B

In the example just shown, the image was successfully pushed to and pulled from the local repository. At this point, you have these choices:

  • If you want to learn more about how the Docker registry works and possibly modify its behavior, skip to the “Configuring a Private Docker Registry” section later in this chapter.
  • If you are ready to start using Docker containers, skip ahead to Chapter 4, “Running Container Images.”

The next section describes how to set up a Docker registry in Ubuntu.

Setting Up a Docker Registry in Ubuntu

Instead of installing a Docker registry from a software package, you can download the registry container from the Docker Hub Registry and use that to provide the Docker registry service. This is a quick and easy way to try out a Docker registry, although the default registry doesn’t scale well for a production environment and is more difficult to configure.

Although this procedure was tested on Ubuntu 14.04, the same basic procedure should work on any Linux system running the Docker service.

To get started here, install Docker as described in Chapter 2, “Setting Up a Container Run-Time Environment,” and start up the Docker service. I suggest you open two Terminal windows (shells) to do this procedure. Open one where you plan to run the registry service, so you can watch it in progress as you start up and test it. Open another Terminal, from which you can push and pull images.

  1. Get the registry image: Run the docker pull command as follows to pull the registry image from the Docker Hub Registry (see Chapter 5, “Finding, Pulling, Saving, and Loading Container Images,” for a description of docker pull):

    $ sudo docker pull registry:latest
    Pulling repository registry
    204704ce3137: Download complete
    e9e06b06e14c: Download complete
    ...
  2. Run the registry image: To try out the Docker registry, run the image in the foreground so you can watch messages produced as the container image is running (see Chapter 4 for a description of docker run). This command starts the latest registry image, exposes TCP port 5000 on the system so clients outside the container can use it, and runs it as a foreground process in the first terminal:

    $ sudo docker run -p 5000:5000 registry:latest
    [2015-05-25 21:33:35 +0000][1][INFO] Starting gunicorn 19.1.1
    [2015-05-25 21:33:35 +0000][1][INFO] Listening at:
    http://0.0.0.0:5000 (1)
    [2015-05-25 21:33:35 +0000][1][INFO] Using worker: gevent
    ...
  3. Get an image: To test that you can push and pull images, open a second Terminal window. A common image used to test Docker is the hello-world image available from the Docker Hub Registry. Run that image as follows (which pulls that image to the local system and runs it):

    $ sudo docker run --name myhello hello-world
    Pulling repository hello-world
    91c95931e552: Download complete
    a8219747be10: Download complete
    Hello from Docker.
    This message shows that your installation appears to be working
    correctly.
    ...
  4. Tag the image: Use docker tag to give the image a name that you can use to push it to the Docker registry on the local system:

    $ sudo docker tag hello-world localhost:5000/hello-me:latest
  5. Push the image: To push the hello-world to the local Docker registry, type the following:

    $ sudo docker push localhost:5000/hello-me:latest
    The push refers to a repository [localhost:5000/hello-me] (len: 1)
    ...
    Pushing tag for rev [91c95931e552] on
         {http://localhost:5000/v1/repositories/hello-me/tags/latest}
  6. Check the Docker registry log messages: If the image was pushed to the registry successfully, in the first Terminal you should see messages showing PUT commands succeeding. For example:

    172.17.42.1 - - [25/May/2015:22:12:37 +0000] "PUT
    /v1/repositories/hello-me/images HTTP/1.1" 204 - "-" "docker/1.0.1
    go/go1.2.1 git-commit/990021a kernel/3.13.0-24-generic os/linux
    arch/amd64"
  7. Pull the image: To make sure you can retrieve the image from the registry, in the second Terminal remove the image from your system, and then try to retrieve it from your local registry:

    $ sudo docker rm myhello
    $ sudo docker rmi hello-world localhost:5000/hello-me:latest
    $ sudo docker pull localhost:5000/hello-me:latest
    Pulling repository localhost:5000/hello-me
    91c95931e552: Download complete
    a8219747be10: Download complete
    # docker images
    REPOSITORY              TAG    IMAGE ID     CREATED     VIRTUAL SIZE
    localhost:5000/hello-me latest 91c95931e552 5 weeks ago 910 B
  8. Run the docker registry again: Instead of running the registry image in the foreground, holding the Terminal open, you can have it run more permanently in the background (-d). To do that, close the running registry container and start a new image as follows:

    $ sudo docker run -d -p 5000:5000 registry:latest

The Docker registry is running in the background now, ready to use. At this point, you have these choices:

  • If you want to learn more about how the Docker registry works and possibly modify its behavior, skip to the “Configuring a Private Docker Registry” section later in this chapter.
  • If you are ready to start using Docker containers, skip ahead to Chapter 4.

The next section describes how to set up a Docker registry in other Linux distributions.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020