Create Dockerrun.aws.json file for AWS
by John Vincent
Posted on June 3, 2021
AWS requires file Dockerrun.aws.json
to enable the deployment of multiple Docker containers.
This is part of a series of discussions regarding Deploying TaskMuncher, a React and Node application, to a Multi-Container Docker Environment at AWS using Dockerhub and Travis CI
For more details, please see Overview of Create Multi-Container Docker TaskMuncher Application at AWS
Please review AWS Production Architecture.
Overview
Add the information about the Amazon S3 bucket that contains the authentication file in the authentication parameter of the Dockerrun.aws.json
file. Make sure that the authentication parameter contains a valid Amazon S3 bucket and key.
Ensure Upload TaskMuncher Docker .dockercfg to AWS has been completed before proceeding.
Dockerrun
Elastic Beanstalk doesn't know how to run containers and so it hands it off to Amazon Elastic Container Service (ECS)
.
ECS uses Dockerrun.aws.json
, a task definition to run each container.
- Version 1 of the Dockerrun.aws.json format is used to launch a single Docker container to an Elastic Beanstalk environment.
- Version 2 adds support for multiple containers per Amazon EC2 instance and can only be used with the multi-container Docker platform.
Thus use version 2.
Create file Dockerrun.aws.json
in base folder of the github repository.
{
"AWSEBDockerrunVersion": 2,
"authentication": {
"bucket": "elasticbeanstalk-us-east-1-971716655829",
"key": "dockercfg.taskmuncher/.dockercfg"
},
"containerDefinitions": [
{
"name": "client",
"image": "johnvincentio/taskmuncher:client",
"hostname": "client",
"essential": false,
"memory": 128
},
{
"name": "server",
"image": "johnvincentio/taskmuncher:server",
"hostname": "api",
"essential": false,
"links": ["mongodb"],
"memory": 128
},
{
"name": "mongodb",
"image": "johnvincentio/taskmuncher:mongodb",
"hostname": "mongodb",
"essential": true,
"portMappings": [
{
"hostPort": 27017,
"containerPort": 27017
}
],
"memory": 128
},
{
"name": "mongo-client",
"image": "johnvincentio/taskmuncher:mongo-client",
"hostname": "mongo-client",
"essential": false,
"links": ["mongodb"],
"memory": 128
},
{
"name": "nginx",
"image": "johnvincentio/taskmuncher:nginx",
"hostname": "nginx",
"essential": true,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8100
}
],
"links": ["client", "server"],
"memory": 128
}
]
}
Each section is a container.
-
name
is the container name. -
image
is the Dockerhub image name to run in this container. -
hostname
is the url to use to access this image. -
essential: true
means shutdown all containers if this container fails. At least one container must be set totrue
. -
portMappings, hostPort
is the port on the machine that is hosting all of the containers. -
portMappings, containerPort
map to this port in this container. -
links
is a list of containers that depend on this container. Use the container name, not the hostname.
For example, nginx
section links
states that the networking should be created to allow the container nginx
running image johnvincentio/taskmuncher:nginx
to access containers client
and server
.
Notice
"authentication": {
"bucket": "elasticbeanstalk-us-east-1-971716655829",
"key": "dockercfg.taskmuncher/.dockercfg"
}
The values of bucket
and key
are determined by the Upload TaskMuncher Docker .dockercfg to AWS step.
Amazon Elastic Container Service (ECS)
uses Dockerrun.aws.json
to configure and run the containers in Elastic Beanstalk
.
It is very easy to make mistakes with a json file and, if you make a mistake, AWS will not provide useful help. Thus, always verify this file with a JSON Validator.