montjet
montjet

Reputation: 645

How to define "headers" in docker-compose version 3 of the registry image?

I prepared docker-compose.yml for the docker registry and now I want to define some UI microservice for it.

I am using docker-compose version 3 but the instruction is written for version 1 or 2.

I should add to registry microservice some HTTP HEADERS:

    Access-Control-Allow-Origin: ['http://localhost:8080']
    Access-Control-Allow-Credentials: [true]
    Access-Control-Allow-Headers: ['Authorization', 'Accept']
    Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS']

My docker-compose.yml:

version: "3.5" 
networks:
    docker-registry-ui-net:
services: 
    registry:
        restart: always
        image: registry:2
        ports:
            - 5000:5000
        environment:
            REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
            REGISTRY_HTTP_TLS_KEY: /certs/domain.key
            REGISTRY_AUTH: htpasswd
            REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
            REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
        volumes:
            - ./data:/var/lib/registry
            - ./certs:/certs
            - ./auth:/auth
        networks:
            - docker-registry-ui-net
    ui:
        image: joxit/docker-registry-ui:latest
        ports:
            - 8080:80
        environment:
            REGISTRY_TITLE: 'My Private Docker Registry'
            REGISTRY_URL: http://localhost:5000
        depends_on:
            - registry
        networks:
            - docker-registry-ui-net

How can I do it using docker-compose file in version 3?

Upvotes: 1

Views: 1984

Answers (2)

jaredboone
jaredboone

Reputation: 71

You can specify registry HTTP headers using environment variables in your docker-compose.yml file. For example:

version: "3.5" 
services: 
    registry:
        restart: always
        image: registry:2
        environment:
            REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
            REGISTRY_HTTP_TLS_KEY: /certs/domain.key
            REGISTRY_AUTH: htpasswd
            REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
            REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
            REGISTRY_HTTP_HEADERS_Access-Control-Allow-Origin: "['http://localhost:8080']"
            REGISTRY_HTTP_HEADERS_Access-Control-Allow-Credentials: "[true]"
            REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers: "['Authorization', 'Accept']"
            REGISTRY_HTTP_HEADERS_Access-Control-Allow-Methods: "['HEAD', 'GET', 'OPTIONS']"

Upvotes: 0

winterberryice
winterberryice

Reputation: 46

A bit late reply, but maybe someone find it useful

You can override registry config by mounting volume file like in this examle https://github.com/Joxit/docker-registry-ui/tree/main/examples/proxy-headers

mount this file:

      - ./registry-config/credentials.yml:/etc/docker/registry/config.yml

Upvotes: 1

Related Questions