Ultimate Go development container for Visual Studio Code
- Compatible with
amd64,386,arm64,armv6andarmv7CPUs ghcr.io/qdm12/godevcontainer:alpineandghcr.io/qdm12/godevcontainer- Based on Alpine 3.24 (size of 1.21GB)
ghcr.io/qdm12/godevcontainer:debian- Based on Debian Trixie Slim (size of 1.37GB)
- Based on qmcgaw/basedevcontainer
- Based on either Alpine or Debian
- Minimal custom terminal and packages
- See more features
- Go 1.27 code obtained from the latest tagged Golang Docker image
- Go tooling integrating with VS code, all cross built statically from source at the binpot:
- Google's Go language server gopls
- golangci-lint, includes golint and other linters
- dlv
⚠️ only works onamd64andarm64 - gomodifytags
- goplay
- impl
- gotype-live
- gotests
- gopkgs v2
- Terminal Go tools
- Runs as an unprivileged user (
user, uid/gid1000by default, configurable), see Non-root userapk(Alpine) andapt-get(Debian) install packages from that user, no sudo involved
- Cross platform
- Easily bind mount your SSH keys to use with git
- Manage your host Docker from within the dev container, more details at qmcgaw/basedevcontainer
- Compatible with both the Docker and Podman engines
- Extensible with docker-compose.yml
- Comes with extra Go binary tools for a few extra MBs:
kubectl,kubectx,kubens,sternandhelm
- Docker or Podman installed and running
- If you use OSX, share the
~/.sshdirectory and the directory of your project with Docker Desktop
- If you use OSX, share the
- VS code installed
- VS code dev containers extension installed
- Setup your configuration files
-
With style 💯
docker run -it --rm -v "/yourrepopath:/repository" qmcgaw/devtainr:v0.2.0 -dev go -path /repository -name projectnameOr use the built binary
-
Or manually: download this repository and put the .devcontainer directory in your project. It holds a
docker/and apodman/configuration, pick the one matching your container engine.
-
- If you have a .vscode/settings.json, eventually move the settings to
.devcontainer/*/devcontainer.jsonin the"settings"section as .vscode/settings.json take precedence over the settings defined in .devcontainer//devcontainer.json*. - Open the command palette in Visual Studio Code (CTRL+SHIFT+P) and select
Dev Containers: Open Folder in Container...and choose your project directory
The image runs using an unprivileged account user, created by the base image.
💁 In case you need root access, see the root user section
The non root user is configurable with container build arguments, defined both in the Dockerfiles and in the devcontainer.json files:
| Build argument | Default | Description |
|---|---|---|
USERNAME |
user |
account name, home is /home/$USERNAME. Update the "remoteUser" key and mount targets in devcontainer.json to match this one if changed. |
GROUP_NAME |
user |
name of the account's primary group |
USER_UID |
1000 |
user ID of the account |
USER_GID |
1000 |
group ID of the account's primary group ($GROUP_NAME) |
DOCKER_GID |
create a docker group with this GID and put the account in it, to reach a rootful engine's socket, see Container engine |
The unprivileged account:
- owns its home,
/go(itsGOPATH), and the state directories of the package manager, so it can install and remove packages withoutsudoordoas - can write to a directory a package may add or remove a file in (
/usr/local/bin,/etc/ssl/certs,/var/log...), which all belong to$GROUP_NAMEand are group-writable. - can only read and execute files installed in the container image and setup by the container engine
- cannot read
/rootand/etc/shadow
On system package management, note:
- it cannot replace a file the image already has installed, since those keep their root ownership
- for the Debian container, some packages have maintainer scripts that insist on running as root, and will fail to install (i.e.
dbus); the fix is to finish the job as root for exampledocker exec --user root <container-name> sh -c 'apt-get install -y dbus && dpkg --configure -a'
If you need to run a command as root, exec in the container using for example
docker exec --user root <container-name> commandRoot has the same terminal setup as the unprivileged account, given its configuration files are symlinks into /home/user.
Note however that by default the zsh history and ssh files are not symlinked or copied from the unprivileged user to root.
The shell prints Running as root at startup, so you always know which account a terminal belongs to.
See the .devcontainer/README.md document in your repository.
When you extend the image in a Dockerfile, the build runs as the unprivileged account: use USER root before instructions that do need root, and USER user to give it back.
You can create a .devcontainer/docker-compose.yml to create the devcontainer and other containers at the same time:
services:
vscode: # configured in devcontainer.json
build: .
postgres: # example of a database container
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: passwordAnd change the following in your relevant devcontainer.json:
- remove
"build": { "dockerfile": "../Dockerfile" }, - add
"dockerComposeFile": "../docker-compose.yml", - add
"overrideCommand": true, - add
"service": "vscode", - add
"runServices": ["vscode", "postgres"],
Finally, open the command palette in Visual Studio Code (CTRL+SHIFT+P) and select Dev-Containers: Rebuild Container
- qmcgaw/basedevcontainer todos
This repository is under an MIT license unless indicated otherwise.
