How to convert Dockerrun.json v2 to Dockerrun.json v3 for new Docker Amazon Linux 2 Platform?

Viewed 889

I previously used Multicontainer docker with Dockerrun.json v2. But now it is deprecated. AWS recommended Docker Amazon Linux 2 Platform. But it requires Dockerrun.json v3. So how to migrate from v2 to v3 ?. Or shall we can directly use docker-compose.yml,Or need to use Dockerrun.json v1. [with multiple containers].

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [{
    "environment": [{
      "name": "POSTGRES_USER",
      "value": "admin"
    },
      {
        "name": "POSTGRES_PASSWORD",
        "value": "postgres"
      },
      {
        "name": "POSTGRES_DB",
        "value": "somedb"
      }
    ],
    "essential": true,
    "image": "postgres:12-alpine",
    "memory": 300,
    "mountPoints": [{
      "containerPath": "/var/lib/postgresql/data/",
      "sourceVolume": "postgres_data"
    }],
    "name": "db",
    "portMappings": [{
      "containerPort": 5432,
      "hostPort": 5432
    }]
  },
    {
      "essential": true,
      "links": [
        "db"
      ],
      "name": "web",
      "image": "****.dkr.ecr.ap-south-1.amazonaws.com/someimage:latest",
      "memory": 300,
      "portMappings": [{
        "containerPort": 80,
        "hostPort": 80
      }]
    }
  ],
  "volumes": [{
    "host": {
      "sourcePath": "postgres_data"
    },
    "name": "postgres_data"
  }
  ]
} 
2 Answers

Just create docker-compose.yml and don't try to build the image inside the docker-compose.yml. Push your all images into ECR, and just do refer in docker compose.

version: '3'
services:
  web:
    image: ****.dkr.ecr.ap-south-1.amazonaws.com/abc:latest
    ports:
      - "80:80"
    links:
      - db
  db:
    image: postgres:12-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=***db
    ports:
      - "5432:5432"

volumes:
  postgres_data:

Like this

In Amazon Linux 2 Docker platform, docker-compose.yml replaces Dockerrun.json for configuring your application services.

You don't require a Dockerrun.json file if you make available a docker-compose.yml properly configured for Amazon Linux 2 Docker platform in your source bundle and pull images from public registries or ECR repositories accessible to the Elasticbeanstalk application.

If you're pulling images from private container registries, you require an additional Dockerrun.json v3 to configure credentials for pulling images from it.

Related