devpod icon indicating copy to clipboard operation
devpod copied to clipboard

Port forwarding is not working

Open AnhQuanTrl opened this issue 1 year ago • 5 comments

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 Version: v0.4.2
  • Operating System: linux
  • ARCH of the OS: AMD64

DevPod Provider:

  • Local/remote provider: docker

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 avatar Jan 17 '24 17:01 AnhQuanTrl

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 :)

AnhQuanTrl avatar Jan 17 '24 17:01 AnhQuanTrl

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

pascalbreuninger avatar Jan 18 '24 13:01 pascalbreuninger

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?

erikpb avatar Mar 31 '24 05:03 erikpb

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

pascalbreuninger avatar Apr 02 '24 07:04 pascalbreuninger

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.

JanHuege avatar Jul 22 '24 13:07 JanHuege