I'm using eb local run
to locally test out a multicontainer application that I plan on deploying to Elastic Beanstalk. Before deciding to move to EB, I was using docker-compose to spin up the containers. Here's what my docker-compose.yml looked like.
docker-compose.yml:
version: '3.7'
services:
web:
build:
context: ./app
dockerfile: Dockerfile.prod
image: <ECR-Repo>:web
command: gunicorn oddstracker_admin.wsgi:application --bind 0.0.0.0:8000
expose:
- 8000
env_file:
- .env.staging
nginx-proxy:
container_name: nginx-proxy
build: nginx
image: <ECR-Repo>:nginx-proxy
restart: always
ports:
- 443:443
- 80:80
volumes:
- certs:/etc/nginx/certs
- html:/usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
- /var/run/docker.sock:/tmp/docker.sock:ro
depends_on:
- web
nginx-proxy-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
env_file:
- .env.staging.proxy-companion
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- certs:/etc/nginx/certs
- html:/usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
depends_on:
- nginx-proxy
volumes:
certs:
html:
vhost:
An important aspect (at least what I think is important) is that the nginx-proxy
service depends on the web
and the nginx-proxy-letsencrypt
service depends on nginx-proxy
. This ensured that each container would not spin up until the previous one was ready.
When I moved to EB, I was forced to write a Dockerrun.aws.json file in order to run eb local run
. Here it is.
Dockerrun.aws.json:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"command": [
"gunicorn",
"oddstracker_admin.wsgi:application",
"--bind",
"0.0.0.0:8000"
],
"essential": true,
"image": "<ECR-Repo>:web",
"name": "web"
},
{
"essential": true,
"image": "<ECR-Repo>:nginx-proxy",
"mountPoints": [
{
"containerPath": "/etc/nginx/certs",
"sourceVolume": "Certs"
},
{
"containerPath": "/usr/share/nginx/html",
"sourceVolume": "Html"
},
{
"containerPath": "/etc/nginx/vhost.d",
"sourceVolume": "Vhost"
},
{
"containerPath": "/tmp/docker.sock",
"sourceVolume": "VarRunDocker_Sock"
}
],
"name": "nginx-proxy",
"portMappings": [
{
"containerPort": 443,
"hostPort": 443
},
{
"containerPort": 80,
"hostPort": 80
}
],
"links": [
"web"
]
},
{
"essential": true,
"image": "jrcs/letsencrypt-nginx-proxy-companion",
"mountPoints": [
{
"containerPath": "/var/run/docker.sock",
"sourceVolume": "VarRunDocker_Sock"
},
{
"containerPath": "/etc/nginx/certs",
"sourceVolume": "Certs"
},
{
"containerPath": "/usr/share/nginx/html",
"sourceVolume": "Html"
},
{
"containerPath": "/etc/nginx/vhost.d",
"sourceVolume": "Vhost"
}
],
"name": "nginx-proxy-letsencrypt",
"links": [
"nginx-proxy"
]
}
],
"family": "",
"volumes": [
{
"host": {
"sourcePath": "certs"
},
"name": "Certs"
},
{
"host": {
"sourcePath": "html"
},
"name": "Html"
},
{
"host": {
"sourcePath": "vhost"
},
"name": "Vhost"
},
{
"host": {
"sourcePath": "/var/run/docker.sock"
},
"name": "VarRunDocker_Sock"
}
]
}
When it autogenerates a docker-compose.yml to run the application, there is no way to provide a depends_on
flag for the various services. Specifically, when I run eb local run
, nginx-proxy-letsencrypt
runs before nginx-proxy
is able to finish and fails the entire process.
So my question: Has anyone found a way to solve this issue, possibly with an additional set of commands within their Dockerrun.aws.json?