.. | ||
.dockerignore | ||
devcontainer.json | ||
docker-compose.yml | ||
Dockerfile | ||
README.md |
Development container
Development container that can be used with VSCode.
It works on Linux, Windows and OSX.
Requirements
- VS code installed
- VS code remote containers extension installed
- Docker installed and running
- Docker Compose installed
Setup
-
Create the following files on your host if you don't have them:
touch ~/.gitconfig ~/.zsh_history
Note that the development container will create the empty directories
~/.docker
,~/.ssh
and~/.kube
if you don't have them. -
For Docker on OSX or Windows without WSL: ensure your home directory
~
is accessible by Docker. -
For Docker on Windows without WSL: if you want to use SSH keys, bind mount your host
~/.ssh
to/tmp/.ssh
instead of~/.ssh
by changing thevolumes
section in the docker-compose.yml. -
Open the command palette in Visual Studio Code (CTRL+SHIFT+P).
-
Select
Remote-Containers: Open Folder in Container...
and choose the project directory.
Customization
Customize the image
You can make changes to the Dockerfile and then rebuild the image. For example, your Dockerfile could be:
FROM qmcgaw/rustdevcontainer
RUN apk add curl
To rebuild the image, either:
- With VSCode through the command palette, select
Remote-Containers: Rebuild and reopen in container
- With a terminal, go to this directory and
docker-compose build
Customize VS code settings
You can customize settings and extensions in the devcontainer.json definition file.
Entrypoint script
You can bind mount a shell script to /home/vscode/.welcome.sh
to replace the current welcome script.
Publish a port
To access a port from your host to your development container, publish a port in docker-compose.yml. You can also now do it directly with VSCode without restarting the container.
Run other services
-
Modify docker-compose.yml to launch other services at the same time as this development container, such as a test database:
database: image: postgres restart: always environment: POSTGRES_PASSWORD: password
-
In devcontainer.json, change the line
"runServices": ["vscode"],
to"runServices": ["vscode", "database"],
. -
In the VS code command palette, rebuild the container.