Local Datastore Emulator with Docker
Updated: August 13, 2018
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=my-datastore-emulator --host-port gdatastore:8000 --no-store-on-disk
my-datastore-emulator is your project ID, so you may want to change it. You may also opt to change ports if they’re in conflict with other applications, and similarly you may also remove the
--no-store-on-disk option if you wish to have data persisted on disk.
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
Finally you need to set the datastore system environment variables, e.g.:
$ set DATASTORE_DATASET my-datastore-emulator $ set DATASTORE_EMULATOR_HOST_PATH 172.17.0.1:8000/datastore $ set DATASTORE_HOST http://172.17.0.1:8000 $ set DATASTORE_EMULATOR_HOST 172.17.0.1:8000 $ set DATASTORE_PROJECT_ID my-datastore-emulator
You should now be able to use the Docker emulator with whichever Datastore package you’re using (e.g. cloud.google.com/go/datastore), for which it should be enough to provide the Project ID (in our case it’s my-datastore-emulator).
If you’re still having trouble then feel free to open an issue at this repo.