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

Pointing docker url fails #24

Closed
AllanPinheiroDeLima opened this issue Jan 11, 2021 · 9 comments
Closed

Pointing docker url fails #24

AllanPinheiroDeLima opened this issue Jan 11, 2021 · 9 comments

Comments

@AllanPinheiroDeLima
Copy link

AllanPinheiroDeLima commented Jan 11, 2021

I've mounted a dockerfile with all services needed on my server. But the link with gotenberg does not work. Is this the intended behavior ? Below, I'll share my actual code:

docker-compose.yml

services:
  gotenberg:
    image: thecodingmachine/gotenberg:6
    networks:
      - "mps"
    ports:
      - "4000:3000"
  redis:
    image: "redis"
    networks:
      - "mps"
    ports:
      - "6379:6379"
  server:
    image: node:12
    depends_on: 
      - redis
      - gotenberg
    env_file: ".env"
    volumes:
      - "C:\\Users\\allan\\Documents\\github\\mps\\backend\\:/usr/src/app"
    networks:
      - "mps"
    ports:
      - "3001:3001"
      - "9229:9229"
networks:
  mps:
    driver: bridge

And the script I used

        try {
            const convertToPdf = pipe(
                gotenberg("gotenberg"),
                convert,
                office,
                set(filename('result.pdf')),
                please
            )
            const buff = Buffer.from(file.buffer);
            const converted = await convertToPdf({
                [file.originalname]: buff
            });
            
            return converted
        } catch (err) {
            debugger
        }
    }

Am I doing something wrong ?

@yumauri
Copy link
Owner

yumauri commented Jan 11, 2021

Hello!
Gotenberg listens port 3000 by default, and using HTTP protocol, you should define this:

const convertToPdf = pipe(
  gotenberg('http://gotenberg:3000')
  // --8<--

I guess it should work like this, if Docker will resolve name gotenberg inside virtual network.

@AllanPinheiroDeLima
Copy link
Author

Yes, it should, but weirdly enough, it didn't work.
I took the right steps though.... i have put them in the same network, configured the dependencies correctly.
But for some reason, redis does work, but gotenberg does not.

I will try something different now

@yumauri
Copy link
Owner

yumauri commented Jan 12, 2021

Did you change code as I suggested? Because in your code you use just gotenberg("gotenberg"), this is wrong.
Also, can you try docker exec bash into container with node application, and use curl here, to connect Gotenberg container from within?

@yumauri
Copy link
Owner

yumauri commented Jan 12, 2021

BTW as far as I know, docker-compose puts all containers from the single docker-compose.yml file into the same virtual network by default, there is no need to do it explicitly.

@yumauri
Copy link
Owner

yumauri commented Jan 12, 2021

Also, maybe Gotenberg needs some time for initialization. Compose's depends_on doesn't wait for service to initialize, it just waits for container to start. If you launch node application right away and trying to connect to Gotenberg immediately — it might be not ready yet.

@AllanPinheiroDeLima
Copy link
Author

BTW as far as I know, docker-compose puts all containers from the single docker-compose.yml file into the same virtual network by default, there is no need to do it explicitly.

Yes, the network part is just because of the defaults that company uses on devops.

Did you change code as I suggested? Because in your code you use just gotenberg("gotenberg"), this is wrong.
Also, can you try docker exec bash into container with node application, and use curl here, to connect Gotenberg container from within?

I did, but it didn't work either. To be honest, I have tried almost everything

Also, maybe Gotenberg needs some time for initialization. Compose's depends_on doesn't wait for service to initialize, it just waits for container to start. If you launch node application right away and trying to connect to Gotenberg immediately — it might be not ready yet.

I did a health check, but with no success. I will try to setup manually and check back to you

@peteralbert
Copy link

@AllanPinheiroDeLima I faced a similar issue: when addressing Gotenberg that ran in Docker directly (e.g. via Postman), everything worked as expected. But with the js client library, I always got a 404 error and Gotenborg was not even reached.

After a long and painful search, I figured that on my local machine were I ran the Gotenberg container, some other app was also running on port 3000! No idea why this did not resulted in some "Address in use" - nor why it worked with Postman - but as soon as changed the port, everything worked smoothly...

@yumauri
Copy link
Owner

yumauri commented Feb 8, 2021

@AllanPinheiroDeLima any updates?

Yesterday I've published version 0.7.0, it has one fix in config merging logic, and introduces new low-level function adjust, with it you can change any internal Request fields.

So, you have two ways for fine tuning:

  • Function gotenberg accepts second argument, where you can specify any http.request options — they will be used internally by default http client.
  • With function adjust you can change any internal Request object fields, for example, url.

And you have third, even more powerful way to change HTTP client behaviour:
You can change default naive http client with completely your own one, for example, on top of got library.
This feature is undocumented, but I can explain in more details, if you need it (in this comment I've written a simple description).

@yumauri
Copy link
Owner

yumauri commented Mar 9, 2021

@AllanPinheiroDeLima I'll close this issue, as far as I reckon it is related to configuration.
But feel free to reopen it in case I'm wrong, or any other updates!

@yumauri yumauri closed this as completed Mar 9, 2021
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