proxy data-container
#
OverviewRunning 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 CTRL+C
).
#
CommandYou can also optionally specify the local port to use
note
For SQL Server the address for the proxied data container is 127.0.0.1
(not localhost
). This is due to SQL Server treating localhost
as a "shared memory" connection which is not supported by the proxy command.
#
TutorialIn 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 localhost
connection spawnctl proxy
will provide.
As a prerequisite you should've followed the instructions to install spawnctl
Create a file
development.yaml
with your data image specifications.In this case we want to create a PostgreSQL data image that is completely empty and is named
dev
.Run the following command to create a data image.
You can verify your data image by running the following command.
Create a data container from the newly created data image.
In a separate terminal, we'll set up the local proxy for this data container.
You should now be able to connect to your database and execute queries over
localhost
on the default engine port.In this example we connect to the PostgreSQL data container (database) using psql.