Skip to content

Instantly share code, notes, and snippets.

@glinton
Last active September 11, 2018 20:16
Show Gist options
  • Save glinton/f0bcb26c8b027996eaacba1aea1c0ea7 to your computer and use it in GitHub Desktop.
Save glinton/f0bcb26c8b027996eaacba1aea1c0ea7 to your computer and use it in GitHub Desktop.
Develop with nanobox while connected to production database

Launch a database in production and connect to it inside local nanobox app.

Create a boxfile with just a database and deploy

boxfile.yml

run.config:
  # set your engine like normal
  engine: none

# define database desired in production
data.db:
  image: nanobox/postgresql:9.5

# not necessary for launching database only, but add for `deploy dry-run`
web.thing:
  start: sleep 1d
  local_only: true
Deploy your database with nanobox
nanobox remote add <myapp>
nanobox deploy

Depending on your setup, you can run nanobox tunnel data.db from your workstation and connect to it from within your local app.

Terminal 1

nanobox tunnel data.db
# listening on port 5432

Terminal 2

# Add database variables from dashboard
nanobox evar add local REMOTE_DB_NANOBOX_USER=nanobox,REMOTE_DB_NANOBOX_PASS=password
nanobox run
#...
# connect to your db
psql -h 192.168.99.1 -U nanobox -d gonano
# Password for user nanobox: 
# psql (9.5.6)
# Type "help" for help.
# 
# gonano=# 

Alternatively, you can always download the linux version of the cli into your web container and tunnel from within that nanobox run and work in another terminal.

Note: This was tested on linux with docker-machine (virtualbox), ymmv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment