Skip to content

Commit ce44331

Browse files
committed
Point to docs from main README
1 parent c1e278f commit ce44331

File tree

1 file changed

+2
-140
lines changed

1 file changed

+2
-140
lines changed

README.md

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -37,144 +37,6 @@ alias dc=devcontainer
3737
complete -F __start_devcontainer dc
3838
```
3939

40-
## Usage
40+
## Docs
4141

42-
### Working with devcontainers
43-
44-
#### Listing devcontainers
45-
46-
To see which running devcontainers the CLI detects you can run the `list` command.
47-
48-
#### Running commands inside a devcontainer
49-
50-
`devcontainer` allows you to run commands in devcontainers. This is similar to `docker exec` but works with devcontainer names (rather than requiring container names/IDs).
51-
52-
For example:
53-
54-
```bash
55-
# Run an interactive bash shell in the vscode-remote-test-dockerfile devcontainer
56-
devcontainer exec --name vscode-remote-test-dockerfile bash
57-
58-
# Run a command with args in the vscode-remote-test-dockercompose_devcontainer/mongo devcontainer
59-
devcontainer exec --name vscode-remote-test-dockercompose_devcontainer/mongo ls -a /workspaces/vscode-remote-test-dockerfile
60-
61-
# Run `bash` in the dev container for the project at `~/ source/my-proj`
62-
devcontainer exec --path ~/source/my-proj bash
63-
64-
# If none of --name/--path/--prompt are specified then `--path .` is assumed (i.e. use the dev container for the current directory)
65-
devcontainer exec bash
66-
67-
# If command/args not set, `bash` is assumed
68-
devcontainer exec --name vscode-remote-test-dockerfile
69-
70-
# Combining these to launch bash in the dev container for the project in the current directory:
71-
devcontainer exec
72-
```
73-
74-
You can use `--prompt` instead of `--name` or `--path` and the CLI will prompt you to pick a devcontainer to run the `exec` command against, e.g.:
75-
76-
```bash
77-
$ ./devcontainer exec ? bash
78-
Specify the devcontainer to use:
79-
0: devcontainer-cli (festive_saha)
80-
1: vscode-remote-test-dockerfile (fervent_gopher)
81-
0
82-
```
83-
84-
You can use this with Windows Terminal profiles:
85-
86-
```json
87-
{
88-
"guid": "{4b304185-99d2-493c-940c-ae74e0f14bba}",
89-
"hidden": false,
90-
"name": "devcontainer exec",
91-
"commandline": "wsl bash -c \"path/to/devcontainer exec --prompt bash\"",
92-
},
93-
```
94-
95-
96-
There are some other benefits of `devcontainer exec` compared to `docker exec`:
97-
- it sets the working directory to be the mount path for the dev container. This can be overridden using `--work-dir`.
98-
- it checks whether you have [configured a user in the dev container](https://code.visualstudio.com/docs/remote/containers-advanced#_adding-a-nonroot-user-to-your-dev-container) and uses this user for the `docker exec`.
99-
- it checks whether you have set up an SSH agent. If you have and VS Code detects it then VS Code will [forward key requests from the container](https://code.visualstudio.com/docs/remote/containers#_using-ssh-keys). In this scenario, `devcontainer exec` configures the exec session to also forward key requests. This enables operations against git remotes secured with SSH keys to succeed.
100-
101-
### Working with devcontainer templates
102-
103-
To work with devcontainer templates `devcontainer` needs to know where you have the templates stored.
104-
105-
As a quickstart, clone the VS Code devcontainers repo: `git clone https://github.com/microsoft/vscode-dev-containers`
106-
107-
Next, run `devcontainer config write` to save a config file and then open `~/.devcontainer-cli/devcontainer-cli.json` in your favourite editor.
108-
109-
The starting configuration will look something like:
110-
111-
```json
112-
{
113-
"templatepaths": []
114-
}
115-
```
116-
117-
Update to include the path to the `containers` folder in the `vscode-dev-containers` repo you just cloned:
118-
119-
```json
120-
{
121-
"templatepaths": ["$HOME/source/vscode-dev-containers/containers"]
122-
}
123-
```
124-
125-
See [Template Paths](#template-paths) for more details of the structure of template folders.
126-
127-
#### Listing templates
128-
129-
Running `devcontainer template list` will show the templates that `devcontainer` discovered
130-
131-
#### Adding a devcontainer
132-
133-
To add the files for a devcontainer definition to your project, change directory to the folder you want to add the devcontainer to and then run:
134-
135-
```bash
136-
# Add the go template
137-
devcontainer template add go
138-
```
139-
140-
This will copy in the template files for you to modify as you wish.
141-
142-
#### Adding a link to a devcontainer
143-
144-
If you are working with a codebase that you don't want to commit the devcontainer definition to (e.g. an OSS project that doesn't want a devcontainer definition), you can use the `template add-link` command. Instead of copying template files it creates symlinks to the template files and adds a `.gitignore` file to avoid accidental git commits.
145-
146-
As with `template add`, run this from the folder you want to add the devcontainer to:
147-
148-
```bash
149-
# Symlink to the go template
150-
devcontainer template add-link go
151-
```
152-
153-
## Template paths
154-
155-
`devcontainer` can be [configured to scan multiple folders](#working-with-devcontainer-templates) to find templates. It is designed to work with folders structured in the same was as the [containers from in github.com/microsoft/vscode-dev-containers](https://github.com/microsoft/vscode-dev-containers/tree/main/containers).
156-
157-
Assuming you cloned [github.com/microsoft/vscode-dev-containers/](https://github.com/microsoft/vscode-dev-containers/) into your `~/source/` folder and set up a custom devcontainer folder in `~/source/devcontainers` then you can configure your template paths as shown below. The sub-folder names are used as the template name and when duplicates are found the first matching folder is taken, so in the example below the `~/source/devcontainers` templates take precedence.
158-
159-
```json
160-
{
161-
"templatepaths": [
162-
"$HOME/source/devcontainers",
163-
"$HOME/source/vscode-dev-containers/containers"
164-
]
165-
}
166-
```
167-
168-
The structure for these template paths is shown in the following tree structure:
169-
170-
```misc
171-
template-collection-folder
172-
|-template1
173-
| |-.devcontainer
174-
| | |-devcontainer.json
175-
| | |-Dockerfile
176-
| | |-<other content for the template>
177-
|-misc-folder
178-
|-<misc content that is ignored as there is no .devcontainer folder>
179-
|-<README or other files that are ignore>
180-
```
42+
See [the documentation](https://stuartleeks.github.io/devcontainer-cli) on how to work with `devcontainer`.

0 commit comments

Comments
 (0)