Run a private docker registry on RHEL 7

Install docker ce if you don’t have one

Start a docker registry container

# Below command will start a docker container running on port 5000, name is registry, image location is /home/user/DockerRegistry
# Change those options accordingly based on your needs
docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /mnt/registry:/home/user/DockerRegistry \

# Now you have a docker registry container running, and can be verified with:
docker ps -a

# Output
CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                                       NAMES
ceb7342c85a8   registry:2   "/ /etc…"   4 seconds ago   Up 3 seconds>5000/tcp, :::5000->5000/tcp   registry

Another example if you need your registry accessible externally and in a secured way. check its official site

If you experience an error when run “docker push …” , eg “unknown blob”

try to check with your domain host provider, below demonstrate a solution for nginx of this issue

# nginx.conf file, update below settings for your domain,
 proxy_set_header X-Forwarded-Proto https;

# and after this if you facing a 413 error, add below configuration in http section (outside server section)
# disable any limits to avoid HTTP 413 for large image uploads
  client_max_body_size 0;
# Restart nginx and you should be ready to go.

Create basic authentication to registry

# Create auth folder
mkdir auth
# Create authentication phrase
docker run \
  --entrypoint htpasswd \
  httpd:2 -Bbn yourusername yourpassword > auth/htpasswd

# Stop the running registry 
docker container stop registry

# Start registry with auth enabled
docker run -d \
  -p 443:5000 \
  --restart=always \
  --name registry \
  -v "$(pwd)"/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  -e \
  -e \
  -v /mnt/registry:/home/user/DockerRegistry \

# Try login with credentials created
docker login

Optional-If you need remote connection for this registry, follow below steps

# Open firewall port for docker registry
sudo firewall-cmd --zone=public --permanent --add-port=5000/tcp
# Reload firewall rule.
sudo firewall-cmd --reload

Then follow below article to create domain or subdomain for your docker registry