Google App Engine on Docker for Development

If you like to use docker for development and you want to run google app engine as a container here is a short tutorial.

This example uses google app engine for python.

Docker Image

First of all we need a Dockerfile to describe the image:


# start from a python 2 official image
FROM python:2
# install unzip, download and unzip google app engine
RUN apt-get update \
&& apt-get install -y unzip \
&& wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.40.zip -P /tmp \
&& unzip -q /tmp/google_appengine_1.9.40.zip -d /opt > /dev/null
# expose application and admin port
EXPOSE 8080 8000
# start google app engine when the container is ran
CMD /opt/google_appengine/dev_appserver.py –host=0.0.0.0 –skip_sdk_update_check=yes –storage_path /usr/share/app/.data /usr/share/app

The Dockerfile should be saved on the root of your project, but don’t name it just Dockerfile otherwise app engine will try to run a container. We will name it project_dockerfile.

Now, from the root of our project, we can build an image out of the Dockerfile:

docker build -t project_image -f project_dockerfile .

Run the container

To run a container based on the freshly built image:

docker run -d -v ${PWD}:/usr/share/app -p 8080:8080 -p 8000:8000 --name=project
project_image
-d

tells docker to run in daemon mode

-v ${PWD}:/usr/share/app

mounts the current folder to the container’s /usr/share/app folder

-p 8080:8080 -p 8000:8000

forwards the 8080 and 8000 ports to the host 8080 and 8000 ports

Install python dependencies

If you need to install python dependencies and your project has a requirements.txt file,

connect to the running container

docker exec -it project /bin/bash

cd to the application folder

cd /usr/share/app

install the dependencies

pip install -r requirements.txt -t lib

and exit

exit

Monitor the application

Of course we want to read the applications log as we test it, we can do this by “attaching” to the running container:

docker attach project

as soon as the application logs we will see it on the console

But.. where is the application?

If you point your browser to 127.0.0.1:8080 you should find your application running.

127.0.0.1:8000 is the address to the google app engine’s administrative console

Data

Google app engine saves the application data to /usr/share/app/.data. Since this is mounted from the project root folder on our host, we will find the .data folder there as well.

This allows the google app engine to find the application data again after the container is stopped and restarted.

Leave a Reply

Your email address will not be published. Required fields are marked *