Running Datastore emulator on Docker

/ / running datastore emulator on docker

Updated: 2017-03-28

Hi there! I use Docker and Google Cloud services for a lot of my development. This article can hopefully help you setup a local Datastore emulator with Docker :)

Setup the Docker container

First things first, run the following command to have your Datastore emulator run in a Docker container

docker run -h gdatastore -p 8000:8000 google/cloud-sdk gcloud beta emulators datastore start --project=pi-docker --host-port gdatastore:8000 --no-store-on-disk

Once that is done, from your host machine run the following command

ip addr show docker0

This will reveal the IP address you can use to access the Datastore emulator. In my case it was 172.17.0.1.

You can then go to the Docker container for which you wish to access the datastore emulator and set it up, e.g.

"datastore": {
  "local": {
    "dataset": "pi-docker",
    "emulator_host_path": "172.17.0.1:8000/datastore",
    "host": "http://172.17.0.1:8000",
    "emulator_host": "172.17.0.1:8000",
    "project_id": "pi-docker"
  }
}

With your golang (or whatever) container you can then run with --publish 6060:8080 parameter, allowing you to access the site on localhost:6060.

Enjoy :)