Docker, AWS Elastic Beanstalk, and RDS

818 views
Skip to first unread message

Jared Marcotte

unread,
Sep 30, 2014, 10:17:20 AM9/30/14
to wag...@googlegroups.com
I try not to ask too many general questions on forums, but I'm hoping that someone out there has already tackled some of these issues. I've always described myself as a "decent programmer and (semi-)passable sysadmin," which, regarding the latter, probably means I know just enough to be dangerous. Putting together our Wagtail site has been great. Now, I need to deploy it and here's where my pain begins.

Reading up on Docker, it sounds like the most promising way to handle dev and deployment that I've ever seen. That said, it's a little beyond me. My end result is to have Elasticsearch and Wagtail running in their own containers on ElasticBeanstalk and using a Postgres RDS as the backend. All sounds well and good in my head, but I'm hoping someone may be able to point me in the direction of a decent primer for this particular stack (or has some firsthand experience). Any and all help would be greatly appreciated. Thanks!

Karl Hobley

unread,
Oct 9, 2014, 5:26:30 AM10/9/14
to wag...@googlegroups.com
Hi Jared,

I've had a look into this for one of my projects. Here's what I did:

I've created a docker base image for Wagtail projects (it's Ubuntu 14.04 with wagtails dependencies installed):
https://registry.hub.docker.com/u/kaedroho/wagtail-base/

I then created a Dockerfile for my project which uses the above base image. It installs uwsgi, then adds the code then installs my projects' dependencies. Here's a stripped down version of it:
https://gist.github.com/kaedroho/5920ddf6751e7c7c5812

And here's the uwsgi.ini that I'm using:
https://gist.github.com/kaedroho/35d69097ff724740692e

Also, in my production settings file, I added some database configuration which picks up the location of the PostgreSQL server from the environment variables that Docker passes to it. You might want to do the same for Elasticsearch/Redis as well:
https://gist.github.com/kaedroho/356c374fc33e6e5e5fac


Here's where it gets a bit tricky... Running migrations and collecting/compressing static files. Here's what I did:


Firstly, build the docker image and tag it:
   # in the folder with the Dockerfile
   $ docker build -t mysite .

You may need to get a cup of coffee as this takes a couple of minutes (later builds would be faster as some steps get cached).

Once it's built, run it and link it to your postgres box:
    $ docker run -d --name mysite-container --link postgres-container:postgres -p 80:80 mysite

You should now be able to browse to the site and see a big fat error message.

To migrate, first make sure you have the database/user setup in postgres (see: https://registry.hub.docker.com/_/postgres/)

Then, run the following:
    $ docker run -ti --link postgres-container:postgres mysite python manage.py syncdb
    $ docker run -ti --link postgres-container:postgres mysite python manage.py migrate

Then finally, you have to collect and compress static files, don't forget the "volumes from" bit:
    $ docker run -ti --volumes-from mysite-container --link postgres-container:postgres mysite python manage.py collectstatic
    $ docker run -ti --volumes-from mysite-container --link postgres-container:postgres mysite python manage.py compress


Hopefully, that will work for you. Most of those docker commands would have to be rerun on every deploy so it might be worth creating a fabfile for it all (which I haven't got round to yet!)

Thanks,

Karl

Jared Marcotte

unread,
Oct 27, 2014, 10:42:45 PM10/27/14
to wag...@googlegroups.com
Hi Karl -

Sorry it's been so long since you posted this here. I can't even begin to tell you how awesome and timely this was to the point I was about to go all Lloyd Dobler on you...minus the creepy factor (ok...maybe there's no way to remove that from the equation) ;)

Good news is, from all of this--I used your base image to get this running--I was able to get the site dockerized and running on Elastic Beanstalk: https://www.votinginfoproject.org

The bad news is that I ended up running into some weird problems that I don't think are Wagtail related and more django-storages & compressor related issues. I can't seem to get them to play well together on the production server (NB: they both work fine on my local container connecting to the remote database, which is confounding since I thought this was one of the issues Docker was supposed to solve).

Anyway, this is just a quick note to say how much I appreciated your work and how it really got me through a very rough Docker-trial-by-fire and site launch :)

Cheers.

- jkm
Reply all
Reply to author
Forward
0 new messages