devcontainers / cli

A reference implementation for the specification that can create and configure a dev container from a devcontainer.json.
https://containers.dev
MIT License
1.37k stars 190 forks source link

forwardPorts configuration option not working #186

Open davidkron opened 1 year ago

davidkron commented 1 year ago

With the recent release (the one with features) I tried experimenting with the devcontainers CLI. But I just can't get the forwardPorts feature to work. I created the following minimal devcontainer.json file:

{
  "name": "my-project-devcontainer",
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
  "features": {
    "ghcr.io/devcontainers/features/sshd:1": {
      "version": "latest"
    }
  },
  "forwardPorts": [2222],
  "remoteUser": "vscode"
}

Maybe I am misunderstanding the forwardPorts option, but I would expect that this configuration will forward the port 2222 (this is the default defined by the sshd feature) from the devcontainer to my host. But a simple ssh localhost -p 2222 did not work.

I tried this on Windows 11.

Frankramos181422 commented 1 year ago

With the recent release (the one with features) I tried experimenting with the devcontainers CLI. But I just can't get the forwardPorts feature to work. I created the following minimal devcontainer.json file:


{

  "name": "my-project-devcontainer",

  "image": "mcr.microsoft.com/devcontainers/base:ubuntu",

  "features": {

    "ghcr.io/devcontainers/features/sshd:1": {

      "version": "latest"

    }

  },

  "forwardPorts": [2222],

  "remoteUser": "vscode"

}

Maybe I am misunderstanding the forwardPorts option, but I would expect that this configuration will forward the port 2222 (this is the default defined by the sshd feature) from the devcontainer to my host. But a simple ssh localhost -p 2222 did not work.

I tried this on Windows 11.

chrmarti commented 1 year ago

Port forwarding is currently not implemented in the CLI. Labelling as feature request.

MunsMan commented 1 year ago

Is there any information about the intent of adding Port Forwarding to the devcontainer CLI?

michaelperel commented 1 year ago

How are you supposed to expose ports, if the option is not supported in devcontainer.json? I have tried looking through the cli tool (most naturally would think it fits in devcontainer up), but have not found anything.

Most simply, I am looking for something equivalent to docker run -p 8080:8080 ….

Something like this feels crucial to support individuals that don’t use vscode, but would rather dev in the container with vim / emacs.

MunsMan commented 1 year ago

@michaelperel, to my knowledge, port forwarding is not supported in the CLI via forward-port. You can use the appPort Option. I implemented basic port forwarding via the docker -p/--publish flag. Currently, it is still living here: https://github.com/MunsMan/devcontainercli/tree/port_forwarding I will do a pull request after I added some testing. If you like, I would love feedback.

I truly agree that the Devcontainer CLI should support workflows independent of VS Code. I'm additionally developing auto-forwarding, but it will probably be a feature, which needs to be added to an Image. We will see.

delijah commented 8 months ago

Any progress on this? Would be awesome to get this feature!