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
- If you don't use Linux or WSL 2, share your home directory
~/and the directory of your project with Docker Desktop
- If you don't use Linux or WSL 2, share your home directory
- Docker Compose installed
- Ensure your host has the following and that they are accessible by Docker:
~/.sshdirectory~/.gitconfigfile (can be empty)
Setup
- 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/godevcontainer
USER root
RUN apk add curl
USER vscode
Note that you may need to use USER root to build as root, and then change back to USER vscode.
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.
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.