Can’t open VS code devcontainer in browser


So, i try to run moodle using VS code devcontainer. When running the docker-compose.yml without VS code, everything works fine but when using VS code to start the containers as devcontainers, i can’t connect to them via the browser (via localhost:80).
Here is the docker-compose.yml file, straight from the bitnami/moodle github:

version: '2.2'
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - MARIADB_USER=bn_moodle
      - MARIADB_DATABASE=bitnami_moodle
      - MARIADB_COLLATE=utf8mb4_unicode_ci
      - 'mariadb_data:/bitnami/mariadb'
      - '80:8080'
      - '443:8443'
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_USER=bn_moodle
      - MOODLE_DATABASE_NAME=bitnami_moodle
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - 'moodle_data:/bitnami/moodle'
      - 'moodledata_data:/bitnami/moodledata'
      - mariadb
    init: true
    driver: local
    driver: local
    driver: local

VS code then generates following docker-compose.yml which i renamed docker-compose.extend.yml and changed the volume path in the .devcontainer folder:

version: '2.2'
  # Update this to the name of the service you want to work with in your docker-compose.yml file
    # If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
    # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks, 
    # debugging) to execute as the user. Uncomment the next line if you want the entire 
    # container to run as this user instead. Note that, on Linux, you may need to 
    # ensure the UID and GID of the container user you create matches your local user. 
    # See for details.
    # user: vscode

    # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer 
    # folder. Note that the path of the Dockerfile and context is relative to the *primary* 
    # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
    # array). The sample below assumes your primary file is in the root of your project.
    # build:
    #   context: .
    #   dockerfile: .devcontainer/Dockerfile

    init: true
      # Update this to wherever you want VS Code to mount the folder of your project
      - ./EnPro://bitnami/moodle/local/enpro:cached

      # Uncomment the next line to use Docker from inside the container. See for details.
      # - /var/run/docker.sock:/var/run/docker.sock 

    # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
    # cap_add:
    #   - SYS_PTRACE
    # security_opt:
    #   - seccomp:unconfined

    # Overrides default command so things don't shut down after the process ends.
    command: /bin/sh -c "while sleep 1000; do :; done"

The last thing generated is the .devcontainer.json where i changed some paths and i also changed some port config while trying to fix the issue:

// For format details, see For config options, see the README at:
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
    "name": "Existing Docker Compose (Extend)",

    // Update the 'dockerComposeFile' list if you have more compose files or use different names.
    // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
    "dockerComposeFile": [

    // The 'service' property is the name of the service for the container that VS Code should
    // use. Update this value and .devcontainer/docker-compose.yml to the real service name.
    "service": "moodle",

    // The optional 'workspaceFolder' property is the path VS Code should open by default when
    // connected. This is typically a file mount in .devcontainer/docker-compose.yml
    "workspaceFolder": "/bitnami/moodle/local/enpro",

    // Set *default* container specific settings.json values on container create.
    "settings": {},

    // Add the IDs of extensions you want installed when the container is created.
    "extensions": [],

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    "forwardPorts": [80],
    //"appPort": [""],

    // Uncomment the next line if you want start specific services in your Docker Compose config.
    // "runServices": [],

    // Uncomment the next line if you want to keep your containers running after VS Code shuts down.
    // "shutdownAction": "none",

    // Uncomment the next line to run commands after the container is created - for example installing curl.
    // "postCreateCommand": "apt-get update && apt-get install -y curl",

    // Uncomment to connect as a non-root user if you've added one. See
    // "remoteUser": "vscode"

    "overrideCommand": false

Edit: After starting the containers manually then attaching VS code to it and the rebuilding via VS code, it has the same problem that it can’t find ‘localhost:80’.

Source: Docker Questions


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us