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 OverflowHow to run docker-compose inside VS Code devcontainer - Stack Overflow
devcontainer docker-compose best practice - Stack Overflow
visual studio code - How to correctly specify multiple docker-compose.yml files in devcontainer.json - Stack Overflow
Clarity on how docker compose based devcontainers are built
Videos
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