Using Elastic Beanstalk with Docker

I just want to write my thoughts off my mind, regarding continuous integration, AWS and Docker.
I’ve used Beanstalk for a long time, and before have used the PHP application versions. Those are good if you want to use PHP and Apache, but customizing the Amazon images are tedious, and you don’t know when your custom image will become unusable after a version upgrade.
So using your own Docker images are perfect for such scenarios, where you want to customize your software.

My images are created for multi user usage, i.e. several WordPress installations should be able to run with the same Docker image. With individual configurations. Another advantage of customizing the container instead of the image, is that the image will also be usable by developers. Developers can just push/copy any git commit/version they like. If the code also was supposed to be pushed into the image, we will end up with an endless bunch of Docker images.

The image itself is not mentioned in the deployment flow.

This is a overview of a sample Elastic Beanstalk and Docker deployment flow:

  • Build source code into a application zip for Beanstalk
  • Upload the application zip to S3
  • Trigger deployment of application to test/staging
  • Trigger deployment of application to production

All these steps are easily done with one Jenkins job for each Beanstalk environment.

In the application zip, we must have a Dockerfile in the root. This file, should include something like:

[sourcecode language=”bash”]
# Example Dockerfile, create your own custom made image
# with the software your application requires.

FROM repository/imagename:version

ADD config/nginx.conf /etc/nginx/nginx.conf
ADD config/sites-enabled/default.conf /etc/nginx/sites-enabled/default.conf
ADD config/conf.d/* /etc/nginx/conf.d/

COPY www /var/www

ENTRYPOINT ["/scripts/"]
CMD ["/bin/bash", "/scripts/"]

In the above example I add custom configuration for Nginx and finally the WordPress source code will be copied to /var/www.
The Dockerfile also runs the file, which can configure anything inside the container before starting the services.
You can for example configure variables for different host, username, password and so on.

If you have several Beanstalk environments, you would likely want to have different database hosts, username and passwords. The script, will set up your container from Beanstalk Software Environment easily.
Just create a few sed commands in the file, and the Docker image can be used in several setups and environments.