generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(src/docker-outside-of-docker): add docker-outside-of-docker feature
- Loading branch information
1 parent
191d15b
commit 19486fa
Showing
13 changed files
with
604 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Limitations | ||
|
||
- As the name implies, the Feature is expected to work when the host is running Docker (or the OSS Moby container engine it is built on). It may be possible to get running in other container engines, but it has not been tested with them. | ||
- The host and the container must be running on the same chip architecture. You will not be able to use it with an emulated x86 image with Docker Desktop on an Apple Silicon Mac, for example. | ||
- This approach does not currently enable bind mounting the workspace folder by default, and cannot support folders outside of the workspace folder. Consider whether the [Docker-in-Docker Feature](../docker-in-docker) would better meet your needs given it does not have this limitation. | ||
|
||
## Supporting bind mounts from the workspace folder | ||
|
||
A common question that comes up is how you can use `bind` mounts from the Docker CLI from within the a dev container using this Feature (e.g. via `-v`). If you cannot use the [Docker-in-Docker Feature](../docker-in-docker), the only way to work around this is to use the **host**'s folder paths instead of the container's paths. There are 2 ways to do this | ||
|
||
### 1. Use the `${localWorkspaceFolder}` as environment variable in your code | ||
|
||
1. Add the following to `devcontainer.json`: | ||
|
||
```json | ||
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" } | ||
``` | ||
|
||
2. Usage with Docker commands | ||
|
||
```bash | ||
docker run -it --rm -v ${LOCAL_WORKSPACE_FOLDER}:/workspace archlinux bash | ||
``` | ||
|
||
3. Usage with Docker-compose | ||
|
||
```yaml | ||
version: '3.9' | ||
|
||
services: | ||
archlinux: | ||
image: archlinux | ||
volumes: | ||
- ${LOCAL_WORKSPACE_FOLDER:-./}:/workspace | ||
``` | ||
- The defaults value `./` is added so that the `docker-compose.yaml` file can work when it is run outside of the container | ||
|
||
### 2. Change the workspace to `${localWorkspaceFolder}` | ||
|
||
- This is useful if we don't want to edit the `docker-compose.yaml` file | ||
|
||
1. Add the following to `devcontainer.json` | ||
|
||
```json | ||
"workspaceFolder": "${localWorkspaceFolder}", | ||
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind" | ||
``` | ||
|
||
2. Rebuild the container. | ||
3. When the container first started with this settings, select the Workspace with the absolute path to the working directory inside the container | ||
4. Docker commands with bind mount should work as they did outside of the devcontainer | ||
|
||
> **Note:** There is no `${localWorkspaceFolder}` when using the **Clone Repository in Container Volume** command in the VS Code Dev Containers extension ([info](https://github.com/microsoft/vscode-remote-release/issues/6160#issuecomment-1014701007)). | ||
|
||
## OS Support | ||
|
||
This Feature should work on recent versions of Arch Linux-based distributions with the `pacman` package manager installed. | ||
|
||
`bash` is required to execute the `install.sh` script. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"id": "docker-outside-of-docker", | ||
"version": "0.1.0", | ||
"name": "Docker (docker-outside-of-docker)", | ||
"documentationURL": "https://github.com/bartventer/devcontainer-features/tree/main/src/docker-outside-of-docker", | ||
"licenseURL": "https://github.com/bartventer/devcontainer-features/blob/main/LICENSE", | ||
"description": "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands.", | ||
"options": { | ||
"version": { | ||
"type": "string", | ||
"proposals": [ | ||
"latest", | ||
"none", | ||
"20.10" | ||
], | ||
"default": "latest", | ||
"description": "Select or enter a Docker/Moby CLI version. (Availability can vary by OS version.)" | ||
}, | ||
"dockerDashComposeVersion": { | ||
"type": "string", | ||
"enum": [ | ||
"none", | ||
"v1", | ||
"v2" | ||
], | ||
"default": "v2", | ||
"description": "Compose version to use for docker-compose (v1 or v2 or none)" | ||
}, | ||
"installDockerBuildx": { | ||
"type": "boolean", | ||
"default": true, | ||
"description": "Install Docker Buildx" | ||
}, | ||
"installDockerComposeSwitch": { | ||
"type": "boolean", | ||
"default": true, | ||
"description": "Install Compose Switch (provided docker compose is available) which is a replacement to the Compose V1 docker-compose (python) executable. It translates the command line into Compose V2 docker compose then runs the latter." | ||
} | ||
}, | ||
"entrypoint": "/usr/local/share/docker-init.sh", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-azuretools.vscode-docker" | ||
] | ||
} | ||
}, | ||
"mounts": [ | ||
{ | ||
"source": "/var/run/docker.sock", | ||
"target": "/var/run/docker-host.sock", | ||
"type": "bind" | ||
} | ||
], | ||
"installsAfter": [ | ||
"ghcr.io/bartventer/devcontainer-features/common-utils" | ||
] | ||
} |
Oops, something went wrong.