5. Dev Container
Developing inside a Container
The Visual Studio Code Remote - Containers extension lets
you use a Docker container as a full-featured development
environment. It allows you to open any folder inside (or
mounted into) a container and take advantage of Visual
Studio Code's full feature set. A devcontainer.json file in
your project tells VS Code how to access (or create) a
development container with a well-defined tool and runtime
stack. This container can be used to run an application or to
separate tools, libraries, or runtimes needed for working
with a codebase.
https://code.visualstudio.com/docs/remote/containers
https://code.visualstudio.com/docs/remote/containers 5
5
17. docker compose
もちろんサポート
例えば、BE開発時にDB起動
例えば、FE開発時にBEモック起動
in devcontainer.json
{
"name": "[Optional] Your project name here",
"dockerComposeFile": "../docker-compose.yml",
"service": "the-name-of-the-service-you-want-to-work-with-in-vscode",
"workspaceFolder": "/default/workspace/path/in/container/to/open",
"shutdownAction": "stopCompose"
}
17
17
https://code.visualstudio.com/docs/remote/create-dev-container#_use-docker-compose
https://code.visualstudio.com/docs/remote/create-dev-container#_use-docker-compose
18. Docker outside of Docker(DooD)
docker composeしていてお隣さんに入りたくなるときは
in docker-compose.yml
volumes: ['/var/run/docker.sock:/var/run/docker.sock']
in Dockerfile
RUN apt-get install docker-ce-cli
RUN chown vscode.vscode /var/run/docker.sock # for no sudo
(セキュリティ上の観点でご利用は計画的に)
18
18
https://github.com/microsoft/vscode-dev-containers/tree/main/containers/docker-from-docker
https://github.com/microsoft/vscode-dev-containers/tree/main/containers/docker-from-docker