vscode can only use one service as "the workspace" where the IDE runs. Just like when working locally you are on the IDE and the other services run in other containers.
None of your current services seem "good" for being the IDE workspace, so you would have to add that one. That would be "just like" your host machine, but in the container.
You can use multiple compose files so you can avoid changing your current docker-compose.yml while being able to add your new service.
So, part I:
- Create a second
docker-compose.ymlfile (maybe:docker-compose.workspace.yml) - Add one single service to that file, maybe call it "workspace". vscode Remote part will run there. What image? You may use one vscode's precooked ones.
- On
.devcontainer.jsonpoint to both files and define the workspace service:
...
"dockerComposeFile": [
"docker-compose.yaml",
"docker-compose.workspace.yaml"
],
"service": "workspace",
...
Ok. So that gives you the workspace container and everything else on the side. That gets us to the other part of the question:
Is it possible to interact with Docker engine on the host from inside the container? So I can simply have a dev.sh script that can simply up the rabbitmq and influxdb dependencies and then launch whatever microservice I want to run?
First, if you want the docker & docker-compose commands you have to install the packages. Some images have them builtin, others not. You may use your own image, etc.
But that is not enough. You workspace container is ignorant of the host's docker. But it is easy enough to fix. Just add a volume mount:
/var/run/docker.sock:/var/run/docker.sock
On the workspace service. That way vscode will "see" your host's docker and operate with it.
Beware that it is still the host's docker, so you may get into trouble with paths, etc depending on what you do.
Answer from marc.fargas on Stack OverflowVideos
vscode can only use one service as "the workspace" where the IDE runs. Just like when working locally you are on the IDE and the other services run in other containers.
None of your current services seem "good" for being the IDE workspace, so you would have to add that one. That would be "just like" your host machine, but in the container.
You can use multiple compose files so you can avoid changing your current docker-compose.yml while being able to add your new service.
So, part I:
- Create a second
docker-compose.ymlfile (maybe:docker-compose.workspace.yml) - Add one single service to that file, maybe call it "workspace". vscode Remote part will run there. What image? You may use one vscode's precooked ones.
- On
.devcontainer.jsonpoint to both files and define the workspace service:
...
"dockerComposeFile": [
"docker-compose.yaml",
"docker-compose.workspace.yaml"
],
"service": "workspace",
...
Ok. So that gives you the workspace container and everything else on the side. That gets us to the other part of the question:
Is it possible to interact with Docker engine on the host from inside the container? So I can simply have a dev.sh script that can simply up the rabbitmq and influxdb dependencies and then launch whatever microservice I want to run?
First, if you want the docker & docker-compose commands you have to install the packages. Some images have them builtin, others not. You may use your own image, etc.
But that is not enough. You workspace container is ignorant of the host's docker. But it is easy enough to fix. Just add a volume mount:
/var/run/docker.sock:/var/run/docker.sock
On the workspace service. That way vscode will "see" your host's docker and operate with it.
Beware that it is still the host's docker, so you may get into trouble with paths, etc depending on what you do.
You would need to add Docker as a feature to your devcontainer.json:
"features": { "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} }
This will allow access to the docker socket on the host.
Working example: devcontainer.json
I am getting started with devcontainer on a project that has two containers, (1) node app and (2) postgres. I have a docker-compose file working for the setup and now trying devcontainers. When I run the docker-compose file within vscode, I cannot manage it with the docker-compose CLI the way I usually do. I don't seem to have as much control over things. But, I can run the containers using the docker-compose CLI and just use vscode to attach to a running container.
What are the pros/cons to these two setups? (1) devcontainer running docker-compose vs (2) docker-compose and vscode attach to running container?