microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.7k stars 1.41k forks source link

Example Issue: Docker-Compose Network #1743

Closed rorychatterton closed 1 year ago

rorychatterton commented 1 year ago

In the example for docker-compose, the use of network_mode is used.

By using this feature, SSHD forwarding (which is required for IntelliJ or the Github CLI to work) does not work properly, remaining stuck in a loop. Tis feature is defined here:

https://github.com/microsoft/vscode-dev-containers/blob/5a084a93b0736ea86395ac99019a5b72a00b6341/container-templates/docker-compose/.devcontainer/docker-compose.yml#L24

Removing this line allows SSHD to forward and fixes this issue.

It is not required for port forwarding using devcontainer json syntax, and inter-connectivity works properly by using the <service_name>:<port> syntax (e.g. db:5432) in the connection string.

Example Configuration:

version: '3.8'
services:
  devcontainer:
    image: mcr.microsoft.com/devcontainers/java:17
    volumes:
      - ../..:/workspaces:cached
    command: /bin/sh -c "while sleep 1000; do :; done"  

  db:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres

volumes:
  postgres-data:

Example working Dev Container -> Postgres Container through the Postgres plugin for VsCode.

Screenshot 2023-05-18 at 4 57 36 pm

Example devcontainer app forwarding:

Screenshot 2023-05-18 at 5 22 53 pm
rorychatterton commented 1 year ago

Closing as not valid anymore. Bad link