spawnctl proxy data-container <container> will configure a
localhost proxy on your machine on the default port for the database engine your data container is running on. For example, if you have a Postgres data container running
spawnctl proxy data-container mypostgrescontainer will open port 5432 on your machine over
localhost and forward all connections to the upstream data container in the Spawn service.
This can be useful for environments where you've already got
localhost connection strings configured and you don't want to manually update the port when data containers are created.
The proxy will run indefinitely until you cancel the command (e.g with
You can also optionally specify the local port to use
For SQL Server the address for the proxied data container is
localhost). This is due to SQL Server treating
localhost as a "shared memory" connection which is not supported by the proxy command.
In this tutorial we will create a data image, then create a data container from that image. We'll then connect to the data container via the
spawnctl proxy will provide.
As a prerequisite you should've followed the instructions to install spawnctl
Create a file
development.yamlwith your data image specifications.sourceType: emptyname: devengine: postgresqlversion: 11.0
In this case we want to create a PostgreSQL data image that is completely empty and is named
Run the following command to create a data image.$ spawnctl create data-image -f ./development.yamlData image 'dev' (10001) created!
You can verify your data image by running the following command.$ spawnctl get data-imagesNAME IMAGE ID ENGINE STATUS MESSAGE CREATEDdev 10001 PostgreSQL 2 Created 2 minutes ago
Create a data container from the newly created data image.$ spawnctl create data-container --image devData container 'dev-rambbomj' (10001) created!-> Host=instances.spawn.cc;Port=53223;User ID=<some_user_id>;Password=<some_password>;
In a separate terminal, we'll set up the local proxy for this data container.$ spawnctl proxy data-container dev-rambbomjcontainer 'dev-rambbomj' is now accessible at localhost:5432
You should now be able to connect to your database and execute queries over
localhoston the default engine port.
In this example we connect to the PostgreSQL data container (database) using psql.$ psql -h localhost -U <some_user_id>Password for user <some_user_id>:psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)Type "help" for help.<some_user_id>=# CREATE TABLE customers(id INT);CREATE TABLE<some_user_id>=# \dtList of relationsSchema | Name | Type | Owner--------+-----------+-------+------------------public | customers | table | <some_user_id>(1 row)