Skip to content

Commit 1d16e35

Browse files
committed
Expand usage docs
1 parent 431ba19 commit 1d16e35

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ sudo -E ./install.sh
2525
To enable bash completion, add the following to you `~/.bashrc` file:
2626

2727
```bash
28-
. <(devcontainer completion)
28+
. <(devcontainer completion bash)
2929
```
3030

3131
## Usage
3232

33-
### Listing devcontainers
33+
### Working with devcontainers
34+
35+
#### Listing devcontainers
3436

3537
To see which running devcontainers the CLI detects you can run the `list` command.
3638

37-
### Running commands inside a devcontainer
39+
#### Running commands inside a devcontainer
3840

3941
`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).
4042

@@ -47,3 +49,55 @@ devcontainer exec vscode-remote-test-dockerfile bash
4749
# Run a command with args in the vscode-remote-test-dockercompose_devcontainer/mongo devcontainer
4850
devcontainer exec vscode-remote-test-dockercompose_devcontainer/mongo ls -a /workspaces/vscode-remote-test-dockerfile
4951
```
52+
53+
### Working with devcontainer templates
54+
55+
To work with devcontainer templates `devcontainer` needs to know where you have the templates stored.
56+
57+
As a quickstart, clone the VS Code devcontainers repo: `git clone https://github.com/microsoft/vscode-dev-containers`
58+
59+
Next, run `devcontainer config write` to save a config file and then open `~/.devcontainer-cli/devcontainer-cli.json` in your favourite editor.
60+
61+
The starting configuration will look something like:
62+
63+
```json
64+
{
65+
"templatepaths": []
66+
}
67+
```
68+
69+
Update to include the path to the `containers` folder in the `vscode-dev-containers` repo you just cloned:
70+
71+
```json
72+
{
73+
"templatepaths": ["$HOME/source/vscode-dev-containers/containers"]
74+
}
75+
```
76+
77+
TODO: Add docs on the folder structure for adding custom templates
78+
79+
#### Listing templates
80+
81+
Running `devcontainer template list` will show the templates that `devcontainer` discovered
82+
83+
#### Adding a devcontainer
84+
85+
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:
86+
87+
```bash
88+
# Add the go template
89+
devcontainer template add go
90+
```
91+
92+
This will copy in the template files for you to modify as you wish.
93+
94+
#### Adding a link to a devcontainer
95+
96+
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.
97+
98+
As with `template add`, run this from the folder you want to add the devcontainer to:
99+
100+
```bash
101+
# Symlink to the go template
102+
devcontainer template add-link go
103+
```

0 commit comments

Comments
 (0)