0

I am almost new to all of this so please excuse my lack of knowledge. I work in Ubuntu with Visual Studio Code and Dev Containers extension to build a docker image of my repository and mount it in a remote container, and develope inside of it. I use for it both a dockerfile and a devcontainer.json files for the settings.

Let's say some member of my new team doesn't want to use vscode and prefers to work through the console. What would be the best approach? Can the remote container be mounted (with devcontainer.json settings) through the console without vscode?

I've tried migrating some of the settings from devcontainer.json to dockerfile (so that the COPY requirements.txt doesn't fail because of paths conflicts when not reading "context": ".." in devcontainer.json, for example) but I still have problems with the working directory, and so on. The goal is that both types of users use the same files for the settings and that it works both in vscode and in the console.

Thanks in advance.

1 Answers1

0

Microsoft provides a tool called Dev Container CLI which allows to build and start the devcontainers by reading the devcontainer.json file. There is no need to maintain an additional Dockerfile.

Basically you install the tool by calling

npm install -g @devcontainers/cli

and after that start the devcontainer with

devcontainer up --workspace-folder <folder>

where folder is the folder that you would have opened in VS code, i.e. with a .devcontainer subdirectory.

This will start the container.

You can interact with the running container by

devcontainer exec --workspace-folder <folder> <command> 

with will execute <command> in the container.

The complete documentation can be found here

MSpiller
  • 3,500
  • 2
  • 12
  • 24
  • Thanks. I tried that option before but I didn't manage to make it work. It works now in an old laptop (but I get "stack smashing detected" error in a new desktop pc when mounting a container). I can build the image with `devcontainer build` (and it installs the docker base image from dockerfile and packages from requirements.txt) but `devcontainer up` just mounts the folder in a container and still runs the packages installed in my host system. I also still don't know how to open a console inside the container. I'll try to move the rest of configuration from `dockerfile` to `devcontainer.json` – leeamtlrd Apr 04 '23 at 08:50
  • Opening a console in the container is done by `devcontainer exec --workspace-folder /bin/sh`, as described above. All commands that should be executed inside the container have to be executed like this. – MSpiller Apr 05 '23 at 08:11