I am following the instructions at https://docs.docker.com/compose/django/ to get a basic dockerized django app going. I am able to run it locally without a problem but I am having trouble to deploy it to AWS using Elastic Beanstalk. After reading here, I figured that I need to translate docker-compose.yml into Dockerrun.aws.json for it to work.
The original docker-compose.yml is
version: '2' services: db: image: postgres web: build: . command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - "8000:8000" depends_on: - db
and here is what I translated so far
{ "AWSEBDockerrunVersion": 2, "volumes": [ { "name": "db" }, { "name": "web" } ], "containerDefinitions": [ { "name": "db", "image": "postgres", "essential": true, "memory": 256, "mountPoints": [ { "sourceVolume": "db" "containerPath": "/var/app/current/db" } ] }, { "name": "web", "image": "web", "essential": true, "memory": 256, "mountPoints": [ { "sourceVolume": "web" "containerPath": "/var/app/current/web" } ], "portMappings": [ { "hostPort": 8000, "containerPort": 8000 } ], "links": [ "db" ], "command": "python manage.py runserver 0.0.0.0:8000" } ] }
but it's not working. What am I doing wrong?
A Dockerrun. aws. json file is an Elastic Beanstalk–specific JSON file that describes how to deploy a set of Docker containers as an Elastic Beanstalk application. You can use a Dockerrun.
Yaml is a superset of json so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the filename to use.
Using the string form causes Docker to run your process using bash which doesn't handle signals properly. Compose always uses the JSON form, so don't worry if you override the command or entrypoint in your Compose file.
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
I was struggling to get the ins and outs of the Dockerrun
format. Check out Container Transform: "Transforms docker-compose, ECS, and Marathon configurations"... it's a life-saver. Here is what it outputs for your example:
{ "containerDefinitions": [ { "essential": true, "image": "postgres", "name": "db" }, { "command": [ "python", "manage.py", "runserver", "0.0.0.0:8000" ], "essential": true, "mountPoints": [ { "containerPath": "/code", "sourceVolume": "_" } ], "name": "web", "portMappings": [ { "containerPort": 8000, "hostPort": 8000 } ] } ], "family": "", "volumes": [ { "host": { "sourcePath": "." }, "name": "_" } ] } Container web is missing required parameter "image". Container web is missing required parameter "memory". Container db is missing required parameter "memory".
That is, in this new format, you must tell it how much memory to allot each container. Also, you need to provide an image - there is no option to build. As is mentioned in the comments, you want to build and push to DockerHub or ECR, then give it that location: eg [org name]/[repo]:latest
on Dockerhub, or the URL for ECR. But container-transform
does the mountPoints
and volumes
for you - it's amazing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With