Why?
You know how to run MicroPython code on awesome hardware like the ESP32 (if not, then read/watch this tutorial). But what if you want to write new code and you don’t have a microcontroller lying around? Or what if you need to prototype a new project, but don’t want to break open your beautiful existing project just to get access to its internal microcontroller?

There are other reasons too – maybe you’re writing a library and want to quickly ensure compatibility with several MicroPython versions. Or you want to add unit testing to your project, but want to run these tests on your computer instead of on a microcontroller. We’ll look into these use cases too, later in this tutorial.
As you may know, MicroPython has been ported to many platforms like the Raspberry Pi Pico, ESP32, and nRF52, to name a few. What you might not know is that it has a unix port as well! This means you can run it on a unix-like operating system such as Linux. But what to do if you’re running Windows on your computer? Read on or watch the video to find out!
1. Creating the Docker container
This is where Docker comes in! In addition to being a cute whale, Docker gives us the ability to run lightweight virtual machines, in which we can install any OS and run the the unix port of MicroPython. Fret not, though – we won’t have to manually install an OS or the MicroPython port ourselves. That work has already been done for us by the awesome Matt Trentini.
First, of course, you need to install Docker – it’s a simple install. After that, we need to pull the micropython/unix image from DockerHub. When you’re on that page, you’ll notice there are various tagged releases of MicroPython to choose from:

So many to choose from! This is where we see the 2nd benefit of running MicroPython in a container – we can test against different versions of MicroPython. This can be useful if you’re writing a library and want to check if it’s compatible with older MicroPython versions.
Let’s say you want to pull a specific version like v1.18. You can do that using Docker’s command-line tool. It will automatically download all the necessary dependencies and build this Docker image. Try the command below, replacing the version number with the one you need:
> docker pull micropython/unix:v1.18
v1.18: Pulling from micropython/unix
778066204fb7: Pull complete
2f29a06fa4b5: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:cf69287d42d0619853f0f1f96a3c079236820005071187cd69eede6255a055bd
Status: Downloaded newer image for micropython/unix:v