loft-sh / devpod

Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker.
https://devpod.sh
Mozilla Public License 2.0
8.8k stars 335 forks source link

Port forwarding is not working #871

Open AnhQuanTrl opened 9 months ago

AnhQuanTrl commented 9 months ago

What happened?
I could not access a forwarded port from a postgres container using docker-compose and devpod.

What did you expect to happen instead?
I should be able to access the forwarded port (5432) at localhost.

How can we reproduce the bug? (as minimally and precisely as possible)

My devcontainer.json:

{
  "dockerComposeFile": "docker-compose.devcontainer.yml",
  "service": "app",
  "runServices": ["db"],
  "workspaceFolder": "/workspaces",
  "forwardPorts": [1337, "db:5432"]
}

My docker-compose.devcontainer.yml:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: devcontainer.Dockerfile
    env_file:
      - .env

    volumes:
      - .:/workspaces:cached

    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity

  db:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    env_file:
      - .env
      - 
volumes:
  postgres-data:

devcontainer.Dockerfile is just FROM mcr.microsoft.com/devcontainers/javascript-node.

Local Environment:

DevPod Provider:

Anything else we need to know?
I can access the db with port 5432 inside the app container. However, I cannot access the db using port forward from the host. I also don't use VSCode, if that helps. I just install neovim directly inside the workspace container.

AnhQuanTrl commented 9 months ago

It seems like forwardPorts only work with VSCode. I think the doc can be improved a bit so that folks are aware of this. In the meantime, I will just use the good old ports mapping of docker-compose file :)

pascalbreuninger commented 9 months ago

Hi @AnhQuanTrl , thanks for reporting the issue! I think you've hit a missing feature of DevPod with the combination of docker compose name:port syntax. We'll fix this

erikpb commented 6 months ago

Same issue here with errors like "Error port forwarding 80: listen tcp 127.0.0.1:80: bind: permission denied". Is there a way to make this work?

pascalbreuninger commented 6 months ago

hey @erikpb, that's because you need root permissions to bind to port 80 on your host machine. Using another port > 1000 should work

JanHuege commented 2 months ago

Also not working for me with vscode and local docker forwarding port 8000. VSCode shows port being forwarded but I cannot see any port-mapping in the docker dashboard.