swiftlang / swiftlang/docs

Swift Server Guide - Build & Push Docker Image to AWS ECR

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

content migration
Dominant language
Python
Stars
28
Forks
5
Avg merge
18h 33m
Merged PRs (30d)
18

Description

Outline 8. Build & Push Docker Image to AWS ECR

Build & Push Docker Image to AWS ECR

In this chapter, we describe how to build a Docker image using Docker Compose and push it to an AWS ECR repository. Note: The Docker Compose file (aws-hummingbird-docker-compose.yaml) shown below is taken directly from the first chapter's example codes.


Table of Contents


1. Building the Docker Image

Instead of using the traditional docker build command, we now use Docker Compose with a dedicated file named aws-hummingbird-docker-compose.yaml. This file defines the service hummingbird-todos along with the build context, Dockerfile, ports, environment variables, and command.

Below is the content of the aws-hummingbird-docker-compose.yaml file:

services:
  hummingbird-todos:
	  platform: linux/amd64
    build:
      context: .
      dockerfile: hummingbird-docker/Dockerfile
    ports:
      - "8080:8080"
    environment:
      DATABASE_HOST: test-database-instance.cgc65h5r3cov.eu-central-1.rds.amazonaws.com
      DATABASE_PORT: 5432
      DATABASE_USER: postgres
      DATABASE_PASSWORD: postgres
      DATABASE_NAME: postgres
      ROOT_CERT_PATH: eu-central-1-bundle.pem
    command: ["--hostname", "0.0.0.0", "--port", "8080"]

To build the Docker image using this configuration, run the following command:

docker compose -f aws-hummingbird-docker-compose.yaml build

This command reads the compose file, builds the image as defined (using the specified Dockerfile and build context), and prepares the container configuration including ports and environment variables.

After building the image, list all Docker images to verify that the newly built image is named with the folder prefix (e.g. <folder-name>-hummingbird-todos):

docker image ls

2. Creating the AWS ECR Repository

Before tagging and pushing your Docker image, you need to create a repository on AWS ECR.

  1. Using the AWS Console:
    • Navigate to Amazon Elastic Container Registry and select Create repository.
  2. Using the CLI:
    • Execute the following command (we are using web-service-repo as the repository name):
aws ecr create-repository --repository-name web-service-repo
  1. Obtain the Repository URI:
    • After creation, copy the repository URI (e.g., 163008249569.dkr.ecr.eu-central-1.amazonaws.com/web-service-repo).

3. Tagging and Pushing the Docker Image

  1. Tag the Local Image:
    • Tag your local image using the repository URI. Replace <repository_uri> with your actual repository URI:
docker tag <my-local-image-name>:latest <repository_uri>:latest
  • Example:
docker tag hummingbird-todos:latest 163008249569.dkr.ecr.eu-central-1.amazonaws.com/web-service-repo:latest
  1. Authenticate with AWS ECR:
    • Log in to AWS ECR with the following command. Replace <region> and <registry_uri> appropriately (note that <registry_uri> is the repository URI without the path):
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <registry_uri>
  • Example:
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 163008249569.dkr.ecr.eu-central-1.amazonaws.com
  1. Push the Docker Image:
    • Finally, push the tagged image to your AWS ECR repository:
docker push <repository_uri>:latest
  • Example:
docker push 163008249569.dkr.ecr.eu-central-1.amazonaws.com/web-service-repo:latest

Tip: You can also find these push commands in the AWS Console under Amazon Elastic Container Registry -> Repositories -> select your repository -> View push commands. Note that the commands shown there might use docker build instead of docker compose build.

With these steps, you have successfully built your Docker image using Docker Compose and pushed it to AWS ECR.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the chapter outline in issue #8 as the content specification and locate the Swift Server Guide entry point where chapter 8 belongs. Check aws-hummingbird-docker-compose.yaml, hummingbird-docker/Dockerfile, and the AWS ECR command examples for consistency. Done means the build, repository creation, authentication, tagging, and push workflow is documented and integrated into the guide.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, docker-compose, swift
Domain
cloud, devops, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.