Skip to main content

proxy data-container


Running 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).


spawnctl proxy data-container <ContainerNames_Or_ContainerIDs>

You can also optionally specify the local port to use

spawnctl proxy data-container <ContainerNames_Or_ContainerIDs> --port 9999

For SQL Server the address for the proxied data container is (not 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 localhost connection spawnctl proxy will provide.

As a prerequisite you should've followed the instructions to install spawnctl

  1. Create a file development.yaml with your data image specifications.

    sourceType: empty
    name: dev
    engine: postgresql
    version: 11.0

    In this case we want to create a PostgreSQL data image that is completely empty and is named dev.

  2. Run the following command to create a data image.

    $ spawnctl create data-image -f ./development.yaml
    Data image 'dev' (10001) created!
  3. You can verify your data image by running the following command.

    $ spawnctl get data-images
    dev 10001 PostgreSQL 2 Created 2 minutes ago
  4. Create a data container from the newly created data image.

    $ spawnctl create data-container --image dev
    Data container 'dev-rambbomj' (10001) created!
    ->;Port=53223;User ID=<some_user_id>;Password=<some_password>;
  5. In a separate terminal, we'll set up the local proxy for this data container.

    $ spawnctl proxy data-container dev-rambbomj
    container 'dev-rambbomj' is now accessible at localhost:5432
  6. 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.

    $ 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);
    <some_user_id>=# \dt
    List of relations
    Schema | Name | Type | Owner
    public | customers | table | <some_user_id>
    (1 row)