Skip to content

Compose name fixed to devcontainer if compose file in .devcontainer/ folder. #11153

@ryush00

Description

@ryush00
  • VSCode Version: 1.103.1
  • Local OS Version: Windows 11 / WSL2 Ubuntu
  • Remote OS Version: Ubuntu 20.04 (Dev Container)
  • Remote Extension/Connection Type: Dev Containers + WSL

Steps to Reproduce:

  1. Clone the same repository into two different directories, e.g. MineList and MineList2.
  2. Each clone has .devcontainer/docker-compose.yml with no name: key.
  3. Open each clone in VS Code and choose "Reopen in Container".
  4. Check project names in Docker Desktop under the container details.

Expected Result:

  • Compose project names should follow the pattern devcontainer_<parent-folder-name>, e.g. devcontainer_minelist and devcontainer_minelist2.

Actual Result:

  • Both environments use the same Compose project name devcontainer.

Additional Context:

  • This seems related to v0.365.0 (pre-release) changed default container name #9866 which fixed .devcontainer folder name handling.
  • No COMPOSE_PROJECT_NAME environment variable is set.
  • My current workaround is to move the docker-compose.yml file to the repository root. This allowed different clones to be recognized separately, but in this case the Compose project name became a long random string instead of the expected pattern, for example:
Image

Does this issue occur when you try this locally?: Yes
Does this issue occur when you try this locally and all extensions are disabled?: Yes

.devcontainer/devcontainer.json
{
    "name": "${localWorkspaceFolderBasename} - MineList",
    "dockerComposeFile": "../docker-compose.yml",
    "service": "web",
    "workspaceFolder": "/workspace",
    "features": {
        "ghcr.io/devcontainers/features/sshd:1": {},
        "ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
            "packages": "libpq-dev, libvips, postgresql-client-15, tmux, imagemagick, ffmpeg"
        },
        "ghcr.io/devcontainers/features/git:1": {
            "version": "latest"
        },
        "ghcr.io/devcontainers/features/ruby:1": {
            "version": "3.3.6"
        },
        "ghcr.io/devcontainers/features/node:1": {
            "version": 20
        },
        "ghcr.io/devcontainers/features/docker-outside-of-docker": {},
        "ghcr.io/devcontainers/features/github-cli:1": {},
		"ghcr.io/dhoeric/features/google-cloud-cli:1": {},
        "ghcr.io/devcontainers/features/common-utils:2": {
            "username": "vscode",
            "userUid": 1000,
            "userGid": 1000,
            "installZsh": true,
            "installOhMyZsh": true,
            "configureZshAsDefaultShell": true,
            "upgradePackages": true
        },
        "ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
            "username": "vscode",
            "plugins": "bundler rails ruby yarn docker git github"
        }
    },
    "customizations": {
        "vscode": {
            "extensions": [
                "github.copilot",
                "Shopify.ruby-lsp",
                "kirillplatonov.erb-toggle",
                "Graphite.gti-vscode",
                "aki77.html-erb",
                "oderwat.indent-rainbow"
            ],
            "settings": {
                "files.watcherExclude": {
                    "**/vendor": true,
                    "**/.git": true,
                    "**/tmp": true
                }
            }
        }
    },

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    "forwardPorts": [3000, 3035, 8080],
    "portsAttributes": {
        "3000": {
            "label": "Rails Server",
            "onAutoForward": "openBrowserOnce"
        },
        "3035": {
            "label": "Webpack Dev Server (via Procfile)"
        },
        "8080": {
            "label": "pgAdmin"
        }
    },

    // Use 'postCreateCommand' to run commands after the container is created.
    "postCreateCommand": ".devcontainer/scripts/boot.sh",
    "postAttachCommand": ".devcontainer/scripts/setup.sh",
    "updateContentCommand": "bundle install && yarn install && bin/rails db:setup",
    "hostRequirements": {
        "cpus": 8,
        "memory": "16gb"
    }

    // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    //"remoteUser": "vscode"
}
.devcontainer/Dockerfile
version: '3'
services:
  redis:
    image: redis
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    #networks:
    #  - UDN_Database
    expose:
      - 80
  postgres:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_HOST_AUTH_METHOD: "trust"
    expose:
      - 5432
  mongodb:
    image: mongo:7
    expose:
      - 27017
    volumes:
      - mongo_data:/data/db
  elasticsearch:
    #image: elasticsearch-nori:7.5.1
    image: elasticsearch:7.5.1
    environment:
      - discovery.type=single-node
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    expose:
      - 9200
    command: >
      /bin/sh -c "./bin/elasticsearch-plugin list | grep -q analysis-nori 
      || ./bin/elasticsearch-plugin install analysis-nori; 
      /usr/local/bin/docker-entrypoint.sh"
  app: &app
    build:
      context: .devcontainer
      dockerfile: Dockerfile
  backend: &backend
    <<: *app
    environment:
      - ELASTICSEARCH_URL=elasticsearch
      - MONGOID_HOST=mongodb
      - REDIS_DB=0
      - REDIS_URL=redis://redis:6379/1
    volumes:
      - .:/workspace:cached
  web:
    <<: *backend
    tty: true
    command: sleep infinity
    expose:
      - 3000
    depends_on:
      - postgres
      - elasticsearch
      - redis
      - mongodb
volumes:
  bundle:
  rails_cache:
  esdata1:
    driver: local
  postgres_data:
  mongo_data:

docker-compose.yml
version: '3'
services:
  redis:
    image: redis
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    #networks:
    #  - UDN_Database
    expose:
      - 80
  postgres:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_HOST_AUTH_METHOD: "trust"
    expose:
      - 5432
  mongodb:
    image: mongo:7
    expose:
      - 27017
    volumes:
      - mongo_data:/data/db
  elasticsearch:
    #image: elasticsearch-nori:7.5.1
    image: elasticsearch:7.5.1
    environment:
      - discovery.type=single-node
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    expose:
      - 9200
    command: >
      /bin/sh -c "./bin/elasticsearch-plugin list | grep -q analysis-nori 
      || ./bin/elasticsearch-plugin install analysis-nori; 
      /usr/local/bin/docker-entrypoint.sh"
  app: &app
    build:
      context: .devcontainer
      dockerfile: Dockerfile
  backend: &backend
    <<: *app
    environment:
      - ELASTICSEARCH_URL=elasticsearch
      - MONGOID_HOST=mongodb
      - REDIS_DB=0
      - REDIS_URL=redis://redis:6379/1
    volumes:
      - .:/workspace:cached
  web:
    <<: *backend
    tty: true
    command: sleep infinity
    expose:
      - 3000
    depends_on:
      - postgres
      - elasticsearch
      - redis
      - mongodb
volumes:
  bundle:
  rails_cache:
  esdata1:
    driver: local
  postgres_data:
  mongo_data:

Metadata

Metadata

Assignees

Labels

containersIssue in vscode-remote containersinfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions