Setting up a VS Code Dev Container - minikube
Tags: vscode, docker, environment, newbie
Published: 2021-10-13 11:13:47

This post builds on what we already learnt in [Setting up a VS Code Dev Container](https://dev.to/benmatselby/setting-up-a-vs-code-dev-container-5fjk). It's more specific goal is to discuss running Dev Containers whilst using [minikube](https://minikube.sigs.k8s.io/docs/) 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:

- [An Overview of Docker Desktop Alternatives.](https://matt-rickard.com/docker-desktop-alternatives/)
- [Goodbye Docker Desktop, Hello Minikube!](https://itnext.io/goodbye-docker-desktop-hello-minikube-3649f2a1c469)

## Recap on getting minikube working

I first had to uninstall Docker Desktop. Once this was done, I used [brew.sh](https://brew.sh/) to install the necessary packages.

```shell
brew install hyperkit
brew install minikube
brew install docker
brew install docker-compose
```

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.

```shell
rm ~/.minikube/config/config.json
```

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

```shell
minikube start
```

Now we need to get Docker talking to minikube

```shell
eval $(minikube -p minikube docker-env)
```

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:

```shell
echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null
```

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:

```text
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: <path to project>
```

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.

```shell
minikube mount "$(pwd)":"$(pwd)"
```

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

- [Setting up a VS Code Dev Container](https://dev.to/benmatselby/setting-up-a-vs-code-dev-container-5fjk)