How do I resolve a Docker push failure while running on a port other than the default (80/443)?

Sometimes a Docker push operation will fail if you are using a port other than the default (80/443).


This issue can happen when the configuration file of Nginx is missing the port variable ($http_host includes both host and port number)

proxy_set_header Host $http_host;

 

Here is a sample of a working configuration of Nginx:

 

server {

    listen 5000 ssl;

    

    ssl_certificate /etc/ssl/my.crt;

    ssl_certificate_key /etc/ssl/my.key;

    ssl_session_cache shared:SSL:1m;

    ssl_prefer_server_ciphers on;

    

    server_name mypublicurl;

    if ($http_x_forwarded_proto = ”) {

        set $http_x_forwarded_proto $scheme;

    }

    ## Application specific logs

    ## access_log /var/log/nginx/mypublicurl-access.log timing;

    ## error_log /var/log/nginx/mypublicurl-error.log;

    rewrite ^/(v1|v2)/(.*) /artifactory/api/docker/docker-local/$1/$2;

    client_max_body_size 0;

    chunked_transfer_encoding on;

    location /artifactory/ {

    proxy_read_timeout 900;

    proxy_pass_header Server;

    proxy_cookie_path ~*^/.* /;

    proxy_pass http://192.168.99.100:8081/artifactory/;

    proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory;

    proxy_set_header X-Forwarded-Port $server_port;

    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;

    proxy_set_header Host $http_host;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

}

 

Please note: Docker’s first request is always for an https configuration with “v1” or “v2”  in the URL path. Only when this configuration is not found, Docker will try and resolve from http.