Install Private Docker Registry on Centos 7

A Docker Registry is a service which you can push Docker images to for storage and sharing. We can deploy our own private Docker Registry behind our firewall with SSL encryption and HTTP authentication. Here we can use centos 7 to install docker registry and using Apache for secure connection with htpasswd.

Docker Private Registry Installation

Docker Private Registry Installation

There are many ways available to install Docker Private Registry on CentOS 7.

Install Docker Private Registry Container

The easiest way to install docker private registry using the container.

Step 1

Install docker

Step 2

Install docker private registry

  • mount registry volume /var/lib/registry


 docker run -d -p 5000:5000 --restart=always --name registry -v <volume-location>:/var/lib/registry registry


# docker run -d -p 5000:5000 --restart=always --name registry -v /var/lib/registry:/var/lib/registry registry

You can connect docker private registry using <hostname/ip>:5000

Browse http://<hostname/ip>:5000/v2/_catalog

Add your registry with docker daemon and push images.

Configure Secure Docker Private Registry

You can use Apache or Nginx web server to configure the registry.

Step 1

Install registry to listening only with localhost.

# docker run -d -p --restart=always --name registry -v /var/lib/registry:/var/lib/registry -v /etc/docker/registry:/etc/docker/registry registry

Step 2

Install Nginx

# yum install epel-release -y
# yum install nginx -y
# cd /etc/nginx/conf.d/
# vi registry.conf
upstream docker-registry {

server {
listen 443 ssl;

ssl_certificate  /etc/nginx/cloudkb.pem;
ssl_certificate_key  /etc/nginx/cloudkb.pem;

# Recommendations from
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

# disable any limits to avoid HTTP 413 for large image uploads
client_max_body_size 0;

# required to avoid HTTP 411: see Issue #1486 (
chunked_transfer_encoding on;

location /v2/ {
# Do not allow connections from docker 1.5 and earlier
# docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
return 404;

# To add basic authentication to v2 use auth_basic setting.
#auth_basic "Registry realm";
#auth_basic_user_file /etc/nginx/.htpasswd;

## If $docker_distribution_api_version is empty, the header will not be added.
## See the map directive above where this variable is defined.
#add_header 'Docker-Distribution-Api-Version' $docker_distribution_api_version always;

proxy_pass http://docker-registry;
proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 900;

Make sure the SSL configuration with your domain name and SSL certificate location.


# ssl_certificate_key

# ssl_certificate

Step 3

Restart Nginx service.

Note: SELinux should be a permissive mode to access proxy.

# setenforce 0

Step 4

It is not required to add with docker deamon. Use this command to login the registry.

# docker login <server_name>

Configure Docker Private Registry with Authentication

Step 1

Install htpasswd and enable user auth.

htpasswd -c /etc/nginx/.htpasswd  guestuser

Step 2

Enable this configuration in registry.conf

#auth_basic “Registry realm”;
#auth_basic_user_file /etc/nginx/.htpasswd;

Step 3 

Restart Nginx service and connect your registry with authentication.

# docker login <server_name>


Install Private Docker Registry on Centos 7

Docker registry OLD V1 version Installation.

Update all packages and install docker registry

#yum update
#yum install docker-registry
#systemctl enable docker-registry.service
#service docker-registry start

Change your customized registry storage path if you required.

vi /etc/docker-registry.yml

search the storage path location and change it.

storage_path =

Once the changes are completed restart docker registry.

To verify the docker registry, use curl command

“\”docker-registry server\””

That’s it!! Your insecure registry is working now.

Browse your Insecure Registry docker registry
Tag your images to push to the registry


#docker tag <imageID>

Run your insecure docker registry with docker

#service docker stop
#docker -d --insecure-registry &


change your docker startup script with insecure registry

#vi /usr/lib/systemd/system/docker.service

add insecure registry url on ExecStart


Example entry

ExecStart=/usr/bin/docker -d $OPTIONS \

Push your images

#docker push

Your images will successfully be pushed to insecure registry

Pull your images

change your docker startup script with insecure registry as per previous step

#docker pull

You are done with insecure registry

Secure Docker Private Registry

In order to use docker registry with secure URL, try to install apache and configure SSL.

install apache with mod SSL.

#yum install httpd mod_ssl

Create user authentication using htpasswd for docker registry

# htpasswd -c /etc/httpd/.htpasswd USERNAME

create your SSL certificate whether Self Signed or valid SSL cert, open your ssl.conf and add proxy settings before </VirtualHost>

#vi /etc/httpd/conf.d/ssl.conf

ProxyRequests off
 ProxyPreserveHost on
 ProxyPass /
 ProxyPassReverse /
<Location />
 Order deny,allow
 Allow from all
AuthName "Registry Authentication"
 AuthType basic
 AuthUserFile "/etc/httpd/.htpassword"
 Require valid-user
# Allow ping and users to run unauthenticated.
 <Location /v1/_ping>
 Satisfy any
 Allow from all
 # Allow ping and users to run unauthenticated.
 <Location /_ping>
 Satisfy any
 Allow from all

Change the valid SSL certificate paths

Now you try to restart httpd service.

# service httpd restart

Browse your registry with SSL and make sure it works.
Now you can login to private registry server

docker login

provide your username and password, the same you provided when creating the htpasswd file.

-Push your images to docker registry

#docker push


Docker registry itself authentication setup

New private docker repository moved as docker distribution. Once you installed docker registry.

Create htpasswd in any file, example /etc/nginx/.htpasswd


# htpasswd -c /etc/nginx/.htpasswd admin

Once done, modify the following docker distribution configuration config

vi /etc/docker-distribution/registry/config.yml

add the additional auth configuration.

 realm: basic-realm
 path: /etc/nginx/.htpasswd


Example config.yml file

version: 0.1
 service: registry
 layerinfo: inmemory
 rootdirectory: /var/lib/registry
 addr: :5000
 realm: basic-realm
 path: /etc/nginx/.htpasswd

Restart docker registry service.

Done, before you push or pull the images. you must log in the Docker registry.

docker login