edgedb / edgedb-docker

Official Docker Image packaging for EdgeDB
81 stars 16 forks source link

Can't remotely connect to docker container #56

Closed briand617 closed 2 years ago

briand617 commented 2 years ago

With my docker-compose.yml set to this on Ubuntu-18:

  edgedb:
    container_name: test_edgedb
    image: edgedb/edgedb
    environment:
      EDGEDB_SERVER_SECURITY: insecure_dev_mode
    volumes:
      - "./dbschema:/dbschema"
      - "./edgedb.toml:/edgedb.toml"
      - "./credentials:/root/.config/edgedb/credentials"
    ports:
      - "5656"    

I am able to go into the edgedb shell and create a database and make queries. My username is set to edgedb and my database is named default

However, when I'm outside the edgedb shell, I can't make the remote connection....

$ edgedb --dsn=edgedb://edgedb@localhost:5656/default
Connecting to an EdgeDB instance at localhost:5656...
edgedb error: ClientConnectionFailedError: cannot establish connection for 30s: Connection refused (os error 111)

Likewise, from another docker container running a Typescript image, I get corresponding errors when I use this connection:

    const client = edgedb.createClient({
      dsn: 'edgedb://edgedb@edgedb:5656/default'
    });

Is there a working example of remote EdgeDB connections within the context of a Docker container environment?

elprans commented 2 years ago

Seems like you need to put 5656:5656 instead of just 5656 in the ports list.

elprans commented 2 years ago

Also, renaming the default database is generally not recommended (unless you have a specific reason), as this only complicates the workflows.

briand617 commented 2 years ago

Thank you, the mis-configured port was definitely part of the problem. Please note then that the instructions https://www.edgedb.com/docs/guides/deployment/docker are incorrect

And I was calling the default database "default" but I guess it's actually "edgedb"?

When I try to connect now, I get

$ edgedb --dsn=edgedb://edgedb@localhost:5656
[2022-04-18T20:50:15Z WARN  rustls::session] Sending fatal alert BadCertificate
edgedb error: ClientConnectionFailedError: invalid certificate: UnknownIssuer

But I thought

EDGEDB_SERVER_SECURITY: insecure_dev_mode

made it so I didn't have to do that. How can I make it work like that?

elprans commented 2 years ago

EDGEDB_SERVER_SECURITY specifies the server security mode. On the client side it's either the --tls-security=insecure CLI argument or the EDGEDB_CLIENT_SECURITY=insecure_dev_mode environment variable or the ?tls_security=insecure DSN argument (the latter two also work in the language bindings).

I've pushed a PR to fix the docs to avoid future confusion.

elprans commented 2 years ago

Also, if I may, look into using edgedb project for local development as it handles all this setup automatically.

briand617 commented 2 years ago

That's how I started... but I don't get the "Docker" option that the website infers:

$ edgedb --version
EdgeDB CLI 1.1.1+5bb8bad
$ edgedb project init
No `edgedb.toml` found in `/home/brian/projects/edgedb-test2` or above
Do you want to initialize a new project? [Y/n]
> Y
Specify the name of EdgeDB instance to use with this project [default: edgedb_test2]: 
> edgedb_test2
Checking EdgeDB versions...
Specify the version of EdgeDB to use with this project [default: 1.3]: 
> 1.0
Do you want to start instance automatically on login? [y/n]
> y
┌─────────────────────┬───────────────────────────────────────────────┐
│ Project directory   │ /home/brian/projects/edgedb-test2             │
│ Project config      │ /home/brian/projects/edgedb-test2/edgedb.toml │
│ Schema dir (empty)  │ /home/brian/projects/edgedb-test2/dbschema    │
│ Installation method │ portable package                              │
│ Start configuration │ auto                                          │
│ Version             │ 1.3+5d0197d                                   │
│ Instance name       │ edgedb_test2                                  │
└─────────────────────┴───────────────────────────────────────────────┘
Version 1.3+5d0197d is already installed
Initializing EdgeDB instance...
[systemctl] Created symlink /home/brian/.config/systemd/user/default.target.wants/edgedb-server@edgedb_test2.service → /home/brian/.config/systemd/user/edgedb-server@edgedb_test2.service.
[systemctl] Failed to connect to bus: No such file or directory
Applying migrations...

Edit: added edgedb CLI version

elprans commented 2 years ago

but I don't get the "Docker" option that the website infers

It's just documenting how to use EdgeDB with Docker if you absolutely have to. If you don't, ignore it, edgedb project and (edgedb instance) commands have everything you need to install, initialize, and manage local EdgeDB instances.