How to push docker images to AWS ECR using fabric8 maven plugin while pulling base images from default registry?

1.7k views Asked by At

When configurating the fabric8 maven plugin to push docker images to AWS ECR, we get an error that the "alpine:latest" image cannot be pulled.

Here the relevant part from the maven pom:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <registry>your_aws_id.dkr.ecr.eu-central-1.amazonaws.com</registry>
    <images>
      <image>
        <name>%a:%v-%t</name>
        <build>
          <from>alpine:latest</from>
          <maintainer>a_company_or_person</maintainer>
          ...
        </build>
      </image>
    </images>
  </configuration>
</plugin>

Is it possible to configure the maven fabric8 plugin to push docker images to AWS ECR while pulling from default registry?

1

There are 1 answers

0
AntiTiming On

The respective documentation can be found in the fabric8 'Registry handling' chapter of the fabric8 documentation. For all options regarding setting (push- and pull-)registries, please refer to this manual. This answer will focus on the pushing registry setup.

Instead of defining one registry for pushing and pulling (as done in the question), there are multiple push-only options:

The first option is to use the fabric8 "pushRegistry" configuration parameter to specify the AWS ECR registry:

...
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  ...
  <configuration>
    ...
    <pushRegistry>your_aws_id.dkr.ecr.eu-central-1.amazonaws.com</pushRegistry>
    ...
  </configuration>
</plugin>
...

Of course you need to replace "your_aws_id" with your account id.

Or as second option you can set the docker.push.registry system property accordingly.

A third option is to add the registry as part of the image name.

For authentication you may want to check the AWS ECR credential helper or this stackoverflow question.