In April 2019, Visual Studio Code released a new extension Remote Containers Development which allows you to code with your development environment in a Docker containerLearn more.

Initial setup

In your project:

  1. Create a directory .devcontainer
  2. Create a Dockerfile .devcontainer/Dockerfile
  3. Create a Dev container configuration .devcontainer/devcontainer.json
  4. Install the remote development extension in VS code
  5. Make sure you have Docker installed. If you use Windows, make sure your project is on a partition shared with Docker.


Since Visual Studio Code 1.38 release in August 2019, there is now support for Alpine based dev containers, which is great for size as Alpine is about 5MB!

For Go, I decided to use the language server gopls only and it has been working great so far and bundles all the required tools.

I also wanted a shell based on zsh and oh-my-zsh to feel nice developing in Visual Studio Code.

Finally, I have mapped my SSH keys so that I can interact with git from inside a terminal window in Visual Studio code.

Here comes the Dockerfile:



Setup user

RUN adduser $USERNAME -s /bin/sh -D -u $USER_UID $USER_GID &&
mkdir -p /etc/sudoers.d &&
echo $USERNAME ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME &&
chmod 0440 /etc/sudoers.d/$USERNAME

Install packages and Go language server

RUN apk add -q --update --progress --no-cache git sudo openssh-client zsh
RUN go get -u -v 2>&1

Setup shell

RUN sh -c “$(wget -O-” “” --unattended &> /dev/null
ENV ENV=“/home/$USERNAME/.ashrc”
RUN printf ‘ZSH_THEME=“robbyrussell”\nENABLE_CORRECTION=“false”\nplugins=(git copyfile extract colorize dotenv encode64 golang)\nsource $ZSH/’ > “/home/$USERNAME/.zshrc”
RUN echo “exec which zsh” > “/home/$USERNAME/.ashrc”
USER root


  • This is based on Go 1.13 on Alpine 3.10
  • It runs without root using the user vscode
  • The final image size is only 445MB
  • It contains an ssh client to interact with your Git repositories using SSH keys
  • It runs the zsh with oh-my-zsh shell with a few plugins

Dev container configuration

An example configuration is the following

“name”: “Your project Dev”,
“dockerFile”: “Dockerfile”,
// “appPort”: 8000,
“extensions”: [
“settings”: {
“go.useLanguageServer”: true
“postCreateCommand”: “go mod download”,
“runArgs”: [
// map SSH keys for Git
“-v”, “${env:HOME}/.ssh:/home/vscode/.ssh:ro”

This installs a few extensions in your container and bind mounts in read only your .ssh directory for Git purposes.

Side note: VS code is clever enough to ignore comments in devcontainer.json

It also runs go mod download after the container is setup to download your Go dependencies when the container is ready.

Launching it

Launch it by opening the VS code command palette and select Remote-Containers: Open folder in container… and choose the current folder.

This will build the Docker image, install the VS code dependencies in there and bind mount everything for you!

Finally, you have a terminal running a beautiful zsh inside VS code (open a terminal if you don’t see it).


Just change the Dockerfile to FROM qmcgaw/godevcontainer . Yep, that’s it .

It will just pull the image from Docker Hub, corresponding to my Github repo… Plus I should keep it to the top with new features


I hope you enjoyed this little guide. It took me a few hours to figure it all out so I hope it can save you some time to enjoy a beer instead.

Originally published by Quentin McGaw at


Thanks for reading :heart: If you liked this post, share it with all of your programming buddies! Follow me on Facebook | Twitter

5 Quick and Easy Data Visualizations in Python with Code

Visual Studio Code Settings and Extensions for Faster JavaScript Development

Docker for Absolute Beginners

Docker Basics: Docker Compose

#go #docker #visual-studio #web-development

How to use the Go Dev container for Visual Studio Code
4 Likes119.75 GEEK