Setting up a VS Code Dev Container - minikube

benmatselby

Ben Selby

Posted on October 13, 2021

Setting up a VS Code Dev Container - minikube

This post builds on what we already learnt in Setting up a VS Code Dev Container. It's more specific goal is to discuss running Dev Containers whilst using minikube as a Docker Desktop replacement on the Mac.

There is lots of chatter about the new license for Docker Desktop. The license changes impacts the business I work for. I wanted to know what our options were.

Getting minikube as a drop in replacement for Docker Desktop on the Mac, was relatively straight forward.

Some good articles to read:

Recap on getting minikube working

I first had to uninstall Docker Desktop. Once this was done, I used brew.sh to install the necessary packages.

brew install hyperkit
brew install minikube
brew install docker
brew install docker-compose
Enter fullscreen mode Exit fullscreen mode

I had previously been using minikube, so I had to delete the old config. If you have never used minikube before, or you're happy with your existing config, then ignore the following command.

rm ~/.minikube/config/config.json
Enter fullscreen mode Exit fullscreen mode

Once this was complete, I could start the minikube application.

minikube start
Enter fullscreen mode Exit fullscreen mode

Now we need to get Docker talking to minikube

eval $(minikube -p minikube docker-env)
Enter fullscreen mode Exit fullscreen mode

This command populates the following environment variables (as of the time of writing):

  • DOCKER_TLS_VERIFY
  • DOCKER_HOST
  • DOCKER_CERT_PATH
  • MINIKUBE_ACTIVE_DOCKERD

If you're going to be using minikube going forward, you're going to want the eval command in your dotfiles (.bashrc, or .zshrc, etc). This means you don't need to manually remember to perform the command each time you want to use Docker in a new shell.

Now we need the docker url in our hosts file:

echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null
Enter fullscreen mode Exit fullscreen mode

At this point, running docker run hello-world should run the container.

minikube and VS Code Dev Containers

If you are use to running VS Code Dev Containers, you know that it will build the image, and then run the container before updating your VS Code.

The first time I did this after switching to minikube I got the following error:

Error response from daemon: invalid mount config for type "bind": bind source path does not exist: <path to project>
Enter fullscreen mode Exit fullscreen mode

This is because Docker is trying to interact with the Hyperkit VM. Therefore, we need to share our project (from the host) into the Hyperkit VM.

minikube mount "$(pwd)":"$(pwd)"
Enter fullscreen mode Exit fullscreen mode

You will need to keep this process running whilst you want to use VS Code Dev Containers.

Once you've run the mount command, you can restart your Dev Container, and it should be working fine.

Summary

Docker Desktop is certainly more developer friendly. You install it, and you can kind of forget about it. If you're migrating to minikube there is a little up front work, that can be easily automated. Once it is done, again, you can kind of forget about it. It's also a gateway into Kubernetes, if that is where your path is taking you.

See also

💖 💪 🙅 🚩
benmatselby
Ben Selby

Posted on October 13, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related