Szymon Biliński bio photo

Szymon Biliński

Email Twitter LinkedIn Github Stackoverflow

If you have a Docker infrastructure in AWS, then Amazon ECR is a likely registry option being used in your environment. In this post I’ll show you how to build a Docker image from a simple Scala application using the sbt-native-packager plugin, and how to publish it to Amazon ECR using sbt-ecr.

Once published, the image could be deployed by Amazon ECS or any other service, that can authenticate to Amazon ECR and pull Docker images from it. Note that service deployment isn’t covered by the scope of this article, just the getting my artifact to some repository in an Amazon region part.

Hello World in Docker

Consider a minimal Scala application:

… with a simple build config in build.sbt

We can add Docker capabilities to this SBT project by including the sbt-native-packager plugin in the project/plugins.sbt file:

… and enabling some additional settings for the Docker build itself:

Once set up, you can run sbt docker:publishLocal to build the Docker image and publish it to the local registry.

Publishing to Amazon ECR

Add the ECR plugin to your project/plugins.sbt:

Include the following project settings:

Once everything is set up you can push the image to ECR by running:

Please note, that you may need to set up credentials for the Amazon SDK, if you haven’t done it earlier.