vscode-dev-containers/containers/docker-in-docker
Gergő Rubint 11922dead7
Fix "Add add sudo support.." typo (#1569)
Signed-off-by: Gergő Rubint <gergo@grubint.com>

Signed-off-by: Gergő Rubint <gergo@grubint.com>
2022-08-12 12:54:45 -04:00
..
.devcontainer Fix "Add add sudo support.." typo (#1569) 2022-08-12 12:54:45 -04:00
test-project [Codespaces] docker-from-docker ---> docker-in-docker (#702) 2021-01-07 13:09:53 -08:00
.npmignore [Codespaces] docker-from-docker ---> docker-in-docker (#702) 2021-01-07 13:09:53 -08:00
README.md Update README.md 2021-12-16 09:08:54 -06:00

README.md

Docker in Docker

Summary

Create child containers inside a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.

Metadata Value
Contributors GitHub Codespaces Team
Categories Other
Definition type Dockerfile
Works in Codespaces Yes
Container host OS support Linux, macOS, Windows
Container OS Debian (though Ubuntu could be used instead)
Languages, platforms Any

Note: Your host chip architecture needs to match the your container image architecture for this script to function. Cross-architecture emulation will not work.

Description

Dev containers can be useful for all types of applications including those that also deploy into a container based-environment. While you can directly build and run the application inside the dev container you create, you may also want to test it by deploying a built container image into your local Docker Desktop instance without affecting your dev container.

In many cases, the best approach to solve this problem is by bind mounting the docker socket, as demonstrated in /containers/docker-from-docker. This definition demonstrates an alternative technique called "Docker in Docker".

This definition's approach creates pure "child" containers by hosting its own instance of the docker daemon inside this container. This is compared to the forementioned "docker-from-docker" method (sometimes called docker-outside-of-docker) that bind mounts the host's docker socket, creating "sibling" containers to the current container.

Note: If preferred, you can use the related docker-in-docker/moby-in-moby install script in your own existing Dockerfiles instead.

Running "Docker in Docker" requires the parent container to be run as --privileged. This definition also adds a /usr/local/share/docker-init.sh ENTRYPOINT script that, spawns the dockerd process, so overrideCommand: false also needs to be set in devcontainer.json. For example:

"runArgs": ["--init", "--privileged"],
"overrideCommand": false

Using this definition

The included .devcontainer/Dockerfile can be altered to work with other Debian/Ubuntu-based container images such as node or python. You'll also need to update remoteUser in .devcontainer/devcontainer.json in cases where a vscode user does not exist in the image you select. For example, to use mcr.microsoft.com/vscode/devcontainers/javascript-node, update the Dockerfile as follows:

FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:14

...and since the user in this container is node, update devcontainer.json as follows:

"remoteUser": "node"

Beyond that, just follow these steps to use the definition:

  1. If this is your first time using a development container, please see getting started information on setting up Remote-Containers or creating a codespace using GitHub Codespaces.

  2. Start VS Code and open your project folder or connect to a codespace.

  3. Press F1 select and Add Development Container Configuration Files... command for Remote-Containers or Codespaces.

    Note: If needed, you can drag-and-drop the .devcontainer folder from this sub-folder in a locally cloned copy of this repository into the VS Code file explorer instead of using the command.

  4. Select this definition. You may also need to select Show All Definitions... for it to appear.

  5. Finally, press F1 and run Remote-Containers: Reopen Folder in Container or Codespaces: Rebuild Container to start using the definition.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See LICENSE.