|
16 | 16 |
|
17 | 17 | 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. This example illustrates how you can do this by running CLI commands and using the [Docker VS Code extension](https://marketplace.visualstudio.com/items?itemName=PeterJausovec.vscode-docker) right from inside your dev container.
|
18 | 18 |
|
19 |
| -## Usage |
| 19 | +## How it works / adapting your existing dev container config |
20 | 20 |
|
21 |
| -[See here for information on using this definition with an existing project](https://aka.ms/vscode-remote/containers/getting-started/open). |
| 21 | +You can adapt your own existing development container Dockerfile to support this scenario by following these steps: |
22 | 22 |
|
23 |
| -If you prefer, you can also just look through the contents of the `.devcontainer` folder to understand how to make changes to your own project. |
24 |
| - |
25 |
| -No additional setup steps are required, but note that the included `.devcontainer/Dockerfile` can be altered to work with other Debian/Ubuntu-based container images such as `node` or `python`. First, update the `FROM` statement to reference the new base image. For example: |
26 |
| - |
27 |
| -```Dockerfile |
28 |
| -FROM node:8 |
29 |
| -``` |
30 |
| - |
31 |
| -See the [Docker CE installation steps for Linux](https://docs.docker.com/install/linux/docker-ce/debian/) for details on other distributions. Note that you only need the Docker CLI in this particular case. |
32 |
| - |
33 |
| -## How it works |
34 |
| - |
35 |
| -The trick that makes this work is as follows: |
36 |
| - |
37 |
| -1. First, install the Docker CLI in the container. From `.devcontainer/Dockerfile`: |
| 23 | +1. First, install the Docker CLI in your container. From `.devcontainer/Dockerfile`: |
38 | 24 |
|
39 | 25 | ```Dockerfile
|
40 | 26 | # Install Docker CE CLI
|
41 |
| - RUN apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common \ |
| 27 | + RUN apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release \ |
42 | 28 | && curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - \
|
43 | 29 | && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
|
44 | 30 | && apt-get update \
|
45 | 31 | && apt-get install -y docker-ce-cli
|
46 | 32 |
|
47 | 33 | ```
|
48 | 34 |
|
49 |
| -2. Then just forward the Docker socket by mounting it in the container. From `.devcontainer/devcontainer.json`: |
| 35 | +2. Then just forward the Docker socket by mounting it in the container using `runArgs`. From `.devcontainer/devcontainer.json`: |
50 | 36 |
|
51 | 37 | ```json
|
52 | 38 | "runArgs": ["-v","/var/run/docker.sock:/var/run/docker.sock"]
|
53 | 39 | ```
|
54 | 40 |
|
| 41 | +3. Press <kbd>F1</kbd> and run **Remote-Containers: Rebuild Container** so the changes take effect. |
| 42 | + |
55 | 43 | That's it!
|
56 | 44 |
|
| 45 | +## Using this definition with an existing folder |
| 46 | +
|
| 47 | +There are no special setup steps are required, but note that the included `.devcontainer/Dockerfile` can be altered to work with other Debian/Ubuntu-based container images such as `node` or `python`. Just, update the `FROM` statement to reference the new base image. For example: |
| 48 | +
|
| 49 | +```Dockerfile |
| 50 | +FROM node:8 |
| 51 | +``` |
| 52 | +
|
| 53 | +Beyond that, just follow these steps to use the definition: |
| 54 | +
|
| 55 | +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. |
| 56 | +
|
| 57 | +2. To use VS Code's copy of this definition: |
| 58 | + 1. Start VS Code and open your project folder. |
| 59 | + 2. Press <kbd>F1</kbd> select and **Remote-Containers: Create Container Configuration File...** from the command palette. |
| 60 | + 3. Select the Docker in Docker definition. |
| 61 | + |
| 62 | +3. To use latest-and-greatest copy of this definition from the repository: |
| 63 | + 1. Clone this repository. |
| 64 | + 2. Copy the contents of `containers/docker-in-docker/.devcontainer` to the root of your project folder. |
| 65 | + 3. Start VS Code and open your project folder. |
| 66 | + |
| 67 | +4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs. |
| 68 | + |
| 69 | +5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition. |
| 70 | + |
57 | 71 | ## License
|
58 | 72 |
|
59 | 73 | Copyright (c) Microsoft Corporation. All rights reserved.
|
60 | 74 |
|
61 |
| -Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE). |
| 75 | +Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE). |
0 commit comments