AWS Elastic Beanstalk Docker deployment

3 minute read Published:

Using Amazon Elastic Beanstalk to deploy the Pagure git forge, a Python web application

Elastic Beanstalk in Amazon Web Services provides a straightforward method of performing Docker application deployments by providing a file describing your Docker container.

Here’s an example where I provide an EBS deployment file for the Fedora Pagure git forge.

Docker files

Contents of the Dockerfile I created for Pagure (which is a Python web service):

FROM fedora

RUN dnf update -y
RUN dnf install -y git python-virtualenv libgit2-devel libjpeg-devel gcc libffi-devel redhat-rpm-config
RUN mkdir -p {/pagure,/pagure_log} && git clone /pagure

WORKDIR /pagure

RUN virtualenv pagure_env
RUN source ./pagure_env/bin/activate && pip install pygit2==$(dnf list installed libgit2 | awk '{print $2}' | cut -d$'\n' -f3 | awk -F'.' '{print $1"."$2".*"}') && pip install -r requirements.txt && python && deactivate
RUN sed -i "s/"
ADD ./ /pagure/
ADD ./ /pagure/

EXPOSE 5000 

ENTRYPOINT ["/bin/bash", "/pagure/"]

Contents of

mkdir -p {/pagure_data/repos,/pagure_data/docs,/pagure_data/forks,/pagure_data/tickets,/pagure_data/requests,/pagure_data/remotes}
/pagure/pagure_env/bin/python /pagure/ -c=/pagure/ 2>&1 >> /pagure_log/app.log

I only ever learned about the .dockerignore file from a tip provided on the EBS interface. Here are the contents of the .dockerignore file:

# Elastic Beanstalk Files

Now we bring all of the above together in an EBS file:

  "AWSEBDockerrunVersion": "1",
  "Ports": [
      "WebserverPort": "5000"
  "Volumes": [
      "HostDirectory": "/var/pagure",
      "ContainerDirectory": "/pagure_data"
  "Logging": "/pagure_log"

Run the example

Here’s how to use the EBS command-line tool to deploy Pagure from the directory containing the above files:

$ pip install awsebcli
$ eb init

At this step you will need to create an IAM user and provide the access and secret key. You also need to give the IAM user correct permissions:


Here’s the output of the eb init step:

$ eb init
Select a default region
(default is 3): 1

Select an application to use
1) My First Elastic Beanstalk Application
2) [ Create new Application ]
(default is 2): 2

Enter Application Name
(default is "pagure-docker"): 
Application pagure-docker has been created.

It appears you are using Docker. Is this correct?
(y/n): y

Select a platform version.
1) Docker 1.9.1
2) Docker 1.7.1
3) Docker 1.6.2
(default is 1): 1
Do you want to set up SSH for your instances?
(y/n): y

Select a keypair.
(default is 2): 1

After this step we’ll create and deploy:

$ eb create pagure
Creating application version archive "app-f031-160516_044344".
Uploading pagure-docker/ to S3. This may take a while.
Upload Complete.
Environment details for: pagure
Application name: pagure-docker
Region: us-east-1
INFO: Successfully pulled fedora:latest
INFO: Successfully built aws_beanstalk/staging-app
INFO: Docker container 91a0c4a6d39f is running aws_beanstalk/current-app.
INFO: Environment health has transitioned from Pending to Ok. Initialization completed 6 seconds ago and took 8 minutes.

Now to make any changes to the environment, you can use eb deploy to update the environment:

$ eb deploy

Check the status to find the hosted CNAME:

$ eb status
Environment details for: pagure
  Application name: pagure-docker
  Region: us-east-1
  Deployed Version: app-f031-160516_045431
  Environment ID: e-25jskaq2ik
  Platform: 64bit Amazon Linux 2016.03 v2.1.0 running Docker 1.9.1 Tier: WebServer-Standard
  Updated: 2016-05-16 08:56:04.675000+00:00
  Status: Ready
  Health: Green

Let’s navigate to $CNAME, or in this case,

To browse the EBS data directory, you can SSH to the EC2 container and go to /var/pagure which is the volume we chose to mount in the file.

Finally, to bring down the example, run eb terminate:

$ eb terminate
The environment "pagure" and all associated instances will be terminated.
To confirm, type the environment name: pagure
INFO: terminateEnvironment is starting.