GithubHelp home page GithubHelp logo

remotecontainerwithmultipleapplications's Introduction

Debugging ASP.Net Core + VS Code + docker-compose + Remote Container Extension + Multiple Applications

Debugging the Application

  1. Open the directory that contains the docker-compose.base.yml and other docker compose files with VSCode.
  2. Press F1, and type and select the command Remote-Containers: Open Folder in Container....
  3. A prompt should open for your select a folder. Select the WebApi folder.
  4. This will re-open VSCode with the container.
  5. Put breakpoints, and press F5 to run the applicaton. Alternatively you can go to the Debug tab and press the green play button.
  6. Repeat steps 1-5, but select WebApp folder instead for step 3.
  7. Browse to:

Releasing the Application

  1. Open up a terminal and change the working directory to where the project's docker-compose.base.yml & docker-compose.release.yml.

  2. Edit the .env file. There's various variables you may want to configure to suit your purposes. You can change whether it deploys using development or production configs, or whether it'll set up HTTPS.

  3. Run the below command:

    docker-compose -f docker-compose.base.yml -f docker-compose.release.yml build

    This will build the production-ready image(s), which you can release or push to a docker hub or use for your CI/CD pipeline.

  4. (Optional) To test if the application & image works under release configuration, run the below command to run the containers locally:

    docker-compose -f docker-compose.base.yml -f docker-compose.release.yml up -d

    Now browse to http://localhost:5000

    Note the above port would depend on what you've set for in your .env file.

Problem

The problem with multi-container setup with docker-compose is you can't really use a shared .env file for your docker-compose

Imagine if you have this structure:

  • .docker
  • WebApi
    • .devcontainer.json
    • ... Other source code files
  • WebApp
    • .devcontainer.json
    • ... Other source code files
  • .env
  • docker-compose.base.yml
  • docker-compose.devcontainer.yml
  • docker-compose.release.yml

With the remote - containers extension, if you follow the official instructions here, where you'd use the command Remote-Containers: Open Folder in Container..., it won't actually work and would just error out. The problem is it'll open the folder where the .devcontainer.json file resides. The docker-compose command's working directory would also be where this .devcontainer.json file resides.

The implications of this is it'll try to find and use the .env file from the directory where the .devcontainer.json file resides (which of course, doesn't exists). As it doesn't exist in that directory, the .env file isn't used, meaning the environment variables doesn't get imported, causing the extension to fail.

Thus, currently the only way to get it to work is you'll need to copy your .env file to be where the .devcontainer.json file resides. That is, you'd have the below structure where you .env file is duplicated.

  • .docker
  • WebApi
    • .devcontainer.json
    • .env
    • ... Other source code files
  • WebApp
    • .devcontainer.json
    • .env
    • ... Other source code files
  • docker-compose.base.yml
  • docker-compose.devcontainer.yml
  • docker-compose.release.yml

This can be resolved if the extension lets us specify the option --project-directory for docker-compose.

For more information on --project-directory, see:

remotecontainerwithmultipleapplications's People

Contributors

deltoss avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.