basecamp / kamal

Deploy web apps anywhere.
https://kamal-deploy.org
MIT License
11.59k stars 460 forks source link

(SOLVED) Kamal Proxy cannot be run on port other than 80/443 #989

Closed aarroisi closed 1 month ago

aarroisi commented 1 month ago

In Kamal 1, I used host_port to specify in which port traefik will be run. It worked well. Now I'm trying to migrate to Kamal 2 and I change it to use app_port like so:

...
proxy:
  host: <%= ENV['HOST_RULE'] %>
  app_port: 8001
  healthcheck:
    path: /api/test/
    interval: 5
    timeout: 12
...

But when I run kamal deploy, it shows an error like this: docker: Error response from daemon: container f0af1c4f712bdb6905f707cf2f7dc6f8981d9122372f0cbb1b2a9b1f6327f6fd: endpoint join on GW Network failed: driver failed programming external connectivity on endpoint gateway_53bcdfbd02e1 (19dacb3d01219d4f82dcfc1413fb5f8e69c9deca92ac025666daf779df40c7f0): failed to bind port 0.0.0.0:80/tcp: Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.

It seems like kamal-proxy still tries to bind to port 80, even though I specify it to run on port 8001.

I have tried many things:

Still tries to bind to port 80.

kobaltz commented 1 month ago

app_port doesn't change kamal-proxy's port. Instead, that is for your application container's port that it is going to try and connect to. For example, a default Rails app using Puma will be hosted on port 3000, so you would set the app_port to 3000 to tell kamal-proxy that it needs to connect to the application on port 3000 instead of the default port 80 of the application port.

aarroisi commented 1 month ago

app_port doesn't change kamal-proxy's port. Instead, that is for your application container's port that it is going to try and connect to. For example, a default Rails app using Puma will be hosted on port 3000, so you would set the app_port to 3000 to tell kamal-proxy that it needs to connect to the application on port 3000 instead of the default port 80 of the application port.

Ah, I thought it would be directly analogous to the previous "host_port" on Kamal 1. So now it is not possible to change on which port the kamal-proxy is running?

kobaltz commented 1 month ago

I'm not sure as I don't have any experience with trying to change the kamal-proxy that it's listening on. However, I would probably say that you're on the right path with the KAMAL_PROXY_HTTP_PORT as described in their README.

aarroisi commented 1 month ago

Thanks for the reply. It really breaks my flow since I still need to run nginx/Caddy as the webserver and only only use kamal-proxy (traefik before) for deployment purpose. I used to run traefik on port other than 80/443 and let nginx/Caddy handle that.

andresribeiro commented 1 month ago

Thanks for the reply. It really breaks my flow since I still need to run nginx/Caddy as the webserver and only only use kamal-proxy (traefik before) for deployment purpose. I used to run traefik on port other than 80/443 and let nginx/Caddy handle that.

me too

aarroisi commented 1 month ago

It turns out, we can configure this based on this PR (https://github.com/basecamp/kamal/pull/974), put inside pre-deploy hook. I guess this solves my problem.

andresribeiro commented 1 month ago

@aarroisi is right, but kamal documentation is pretty bad

first, the port that your app is using inside the container. Next uses 3000. so on config/deploy.yml you just

proxy:
  app_port: 3000

now you need to tell kamal which port its proxy should run, so type on your terminal and run

kamal proxy boot_config set --http-port 4444 --https-port 4445

--https-port seems to be required

hope it helps you save your time.