Running Private Docker Registry
I still find it hard to believe how easy it is to run your own infrastructure in the cloud.
Running a Docker registry is as simple as adding a few lines of code to your Terraform configuration.
resource "aws_ecr_repository" "foo" {
name = "bar"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
When deployed, this create an registry where you can manage multiple Docker repositories. You can upload a Docker image to be used in your private ECS cluster:
DOCKER_BUILDKIT=1 docker build -f /path/to/Dockerfile -t jcheng/helloworld:0.0.2 /path/context
docker tag jcheng/helloworld:0.0.2 12345dkr.ecr.us-west-2.amazonaws.com/helloworld:0.0.2
docker push 12345.dkr.ecr.us-west-2.amazonaws.com/helloworld:0.0.2
Then simply add your service definition to your ECS cluster.
resource "aws_ecs_task_definition" "hello_world" {
family = "hello-world-service"
container_definitions = <<TASK_DEFINITION
[
{
"name": "hello_world",
"image": "12345.dkr.ecr.us-west-2.amazonaws.com/helloworld:0.0.2",
...
[snipped]
resource "aws_ecs_service" "hello_world" {
name = "hellow_world_service"
cluster = aws_ecs_cluster.cluster.id
...
[snipped]
You entire infrastructure: A Docker cluster, an image registry, code, and everything you need to run a high availability API all managed with a few Terraform files. Computing is really too good to be true.