Help Understanding Docker Usage with WSL1

Hello,

I am totally new to docker and trying to wrap my head around what it offers and how it can be useful. Many friends have recommended it to me but I find I am struggling. Hopefully someone here can help.

My situation is this. I am running Windows 10 and Windows Subsystem for Linux 1 (WSL1). On WSL1 I am running Ubuntu 20.04.6 LTS. Normally I do all my development in VSCode by opening an instance in WSL1. Changing from WSL1 to WSL2 is not an option right now for me.

I followed this guide for setting up docker on WSL1.

My understanding is Docker can create an isolated sandbox in which I can do development. My expectation is that I somehow “create” such an environment and then I can connect to it via VSCode just like I do with WSL1. The sandbox should already have python installed along with all the packages I need for my development. Then I can start writing scripts, doing calculations, etc. If that isn’t correct, someone please let me know.

To state another way, I expect it will create something like a “mini” WSL1 but with only the stuff installed that I want to use (python in this case). Once this is created, I can hop in, use the terminal, run python files, save stuff to disk, install more packages if I want, etc.

Now as a simple first pass just to see how this works, I wanted to create a container with just python installed and nothing else. Once there I wanted to, for example. create a hello_world.py and run it from the terminal (from within the container, if that makes sense). So I started here but with a pared down Dockerfile, as shown below.

As I understand it, this file tells docker

  1. to create an image used the official docker python image as the base
  2. in the container create a directory called /src (hm, okay but where? /home/USERNAME/src or??? I’m confused by this command)
  3. Expose the correct port according to the guide I linked above
FROM python:3.12
WORKDIR /src
EXPOSE 2375

I open a terminal in WSL1, navigate to where this dockerfile is stored and do docker build -t pytest .
That appears to work. But now when I try to run the container (hitting the little “Play” button in docker desktop) it immediately quits. It doesn’t start running and stay that way so that I can connect to it using VSCode, it just quits with no message as to why. I’m probably missing something obvious here.

I appreciate anyone willing to help me wrap my head around this.

You could run any virtual machine and use Docker CE in that VM. Or if your Windows is not Windows Home, you could use the HyperV backend instead of WSL2, but I didn’t even know Docker Desktop could be installed on a WSL1 distro. It was not designed to run that way.

Since there are comments below the blogpost, you could try to contact the author of that post who hopefully still watches that site.