Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect to database #136

Closed
Miggets7 opened this issue Aug 7, 2023 · 8 comments
Closed

Not able to connect to database #136

Miggets7 opened this issue Aug 7, 2023 · 8 comments

Comments

@Miggets7
Copy link

Miggets7 commented Aug 7, 2023

Hi all,

I've got this config:


{
  "apps": {
    "http": {
    ...
    },
    "layer4": {
      "servers": {
        "srv0": {
          "listen": [":27017"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "proxy",
                  "upstreams": [{ "dial": ["10.0.22.76:27017"] }]
                }
              ]
            }
          ]
        }
      }
    }
  }
}

And I'm trying to connect to a MongoDB instance running in a docker swarm. That's the 10.0.22.76 ip.
But I've got no success in connecting.

I'm using the module in combination with caddy-docker-proxy and caddy-ext/layer4.

This is the docker part:

labels:
        caddy.layer4.:27017.proxy: "{{upstreams 27017}}"

Which produces the global json part mentioned above. Am I missing something?

@mholt
Copy link
Owner

mholt commented Aug 7, 2023

But I've got no success in connecting.

What is the error message? And what's in Caddy's logs?

@Miggets7
Copy link
Author

Miggets7 commented Aug 7, 2023

This is what mongodb compass(client app) returns, after trying for a while:
connection <monitor> to 86.105.245.116:27017 closed
I think it goes into timeout.

I've created a docker image with this Dockerfile:

ARG CADDY_VERSION=2.7.2
FROM caddy:${CADDY_VERSION}-builder AS builder

RUN xcaddy build \
    --with github.com/lucaslorentz/caddy-docker-proxy/v2 \
    --with github.com/mholt/caddy-l4/layer4 \
    --with github.com/RussellLuo/caddy-ext/layer4

FROM caddy:${CADDY_VERSION}-alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

CMD ["caddy", "docker-proxy"]

The ports are open:

services:
  caddy_server:
    image: registry.stofloos.nl/caddy-server
    ports:
      - 80:80
      - 443:443
      - 27017:27017

The caddy server service doesn't show any error regarding the port 27017 or any another error regarding layer4. Don't if I should look in a specific place?

@francislavoie
Copy link
Collaborator

Enable the debug global option for additional logging.

@mholt
Copy link
Owner

mholt commented Aug 7, 2023

If nothing shows up even in the debug logs, then there's a good chance the connection isn't reaching Caddy in the first place. 🤔

@Miggets7
Copy link
Author

Miggets7 commented Aug 8, 2023

After restarting the caddy server, everything started working. So I guess some sort of caching?

@mholt
Copy link
Owner

mholt commented Aug 8, 2023

Interesting. I don't know -- maybe the config you thought was running wasn't actually running / POSTed to the server before the restart? Just a guess. I've done it before. Glad to hear it is working now though! If you can reproduce a bug I'd like to know so we can fix it 😁

@mholt mholt closed this as completed Aug 8, 2023
@Miggets7
Copy link
Author

Miggets7 commented Aug 8, 2023

I'll keep an eye on it. Sorry for the trouble.

Out of curiosity, is this module becoming part of the default caddy server? Cause I think it would be a great addition and make caddy more complete.

@mholt
Copy link
Owner

mholt commented Aug 8, 2023

(No worries. Definitely let me know, like if a config isn't "sticking" like you'd expect. Thanks!)

Out of curiosity, is this module becoming part of the default caddy server? Cause I think it would be a great addition and make caddy more complete.

I agree with you. Maybe someday, but it's not ready yet. (Some bugs like #72 and #132 definitely need to be figured out first.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants