How to configure custom domain name for Amazon ECR

Unfortunately, AWS does not support custom domain names for ECR. You'll have to make do with the auto-generated ones for now. There are 'hacks' about, which centre around Nginx proxies, but it really isn't worth the effort.


If you are using docker-compose, one way to get mitigate the ugly host portion of this is to use ARG in Dockerfile and define your host in .env.

derived/Dockerfile:

ARG REGISTRY_HOST
FROM ${REGISTRY_HOST}/namespace/base:latest
...

.env:

REGISTRY_HOST=99999999999.dkr.ecr.eu-west-1.amazonaws.com

docker-compose.yml:

version: "3.3"
services:

  base-service:
    image: ${REGISTRY_HOST}/namespace/base:latest
    build:
      context: base/

    ...

  derived-service:
    image: ${REGISTRY_HOST}/namespace/derived:latest
    build:
      context: derived/
      args:
        - REGISTRY_HOST=${REGISTRY_HOST}
...

The advantage of putting ${REGISTRY_HOST} in the image declaration is that you can docker-compose push base-service and it will properly push the image to your ECS repo.

None of this is as clean as if AWS allowed custom hostnames for ECS repositories, but it's better than hardcoding that god-awful string in all your Dockerfiles. You could do this without docker-compose as well obviously but you'd have to define the build arg on the command line, something like docker build --build-arg REGISTRY_HOST=99999999999.dkr.ecr.eu-west-1.amazonaws.com ...