Categories: Linux

Testing Mariner Linux on Windows

I recently needed to do some testing on Mariner. To use the docker images, I first installed Docker Desktop for Windows.

Installing Docker Desktop

One of the options it presented was to use WSL 2 instead of Hyper-V. Searching for wsl 2 vs hyper-v docker windows leads to windows 10 – Docker on Hyper-V vs WSL 2 – Super User. Docker addressed this in their post on The Future of Docker Desktop for Windows. Additional system requirements are listed at Install Docker Desktop on Windows.

Building a Mariner Image

Paste the lines below into a Dockerfile. See the Dockerfile reference for more information about Dockerfile commands.

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0

Build the image by running docker build -t testimage . in the directory containing the Dockerfile. The output looks like this (hashes truncated to 16 characters):

$ docker build -t testimage .
[+] Building 24.3s (5/5) FINISHED                                                                        docker:default
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load build definition from Dockerfile                                                               0.2s
 => => transferring dockerfile: 101B                                                                               0.0s
 => [internal] load metadata for mcr.microsoft.com/cbl-mariner/base/core:2.0                                       0.8s
 => [1/1] FROM mcr.microsoft.com/cbl-mariner/base/core:2.0@sha256:799d8ab777f935bf...  23.1s
 => => resolve mcr.microsoft.com/cbl-mariner/base/core:2.0@sha256:799d8ab777f935bf...  0.0s
 => => sha256:799d8ab777f935bf... 860B / 860B                         0.0s
 => => sha256:567f7e473f79bb91... 949B / 949B                         0.0s
 => => sha256:1f28c8aa4ec798df... 1.93kB / 1.93kB                     0.0s
 => => sha256:9b5d7e56a34b835b... 28.33MB / 28.33MB                  14.9s
 => => sha256:682c69bfe8e8c609... 55.46MB / 55.46MB                  22.3s
 => => sha256:51b2f9e22c65add4... 4.46kB / 4.46kB                     0.4s
 => => extracting sha256:9b5d7e56a34b835b...                          1.3s
 => => extracting sha256:682c69bfe8e8c609...                          0.5s
 => => extracting sha256:51b2f9e22c65add4...                          0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:92f91ed651632b21e1e7dbc02de1f55140b3ca1f30ad6da29fa4b62f20a6d807                       0.0s
 => => naming to docker.io/library/testimage

Running Docker

To start a container using the image, use the docker run command. For details on the command line options, see docker run | Docker Documentation. The explanation at How to Use Docker Run Command with Examples (phoenixnap.com) was helpful as well.

docker run -i -t testimage

To view the status of the containers on your machine, run docker ps.

docker ps -a
docker ps --filter status=created
docker ps --filter status=exited

Using a Script

To do all this using a single script, paste these commands into a shell script:

mkdir docker
cd docker
echo "FROM mcr.microsoft.com/cbl-mariner/base/core:2.0" > Dockerfile
docker build -t myimage .
docker run -i -t testimage

Copying Files to the Container

Use docker cp as suggested by How to copy files from host to Docker container? – Stack Overflow.

docker ps
docker cp ~/compressed.tar.gz <containerid>:/myfiles

Starting the Container in Detached Mode

It is sometimes essential to have the container run in detached mode, e.g. when you have a single command line interface available (e.g. via SSH) and don’t want to connect to the host again. Start the container using docker run then connect to it using docker attach.

docker run -dit --name mycontainer testimage
docker attach mycontainer

Installing Components in Mariner

I tried to use the tar command to extract a file copied into the container but it outputs bash: tar: command not found. One of the results from install tar on mariner dockerfile – Search (bing.com) is azure-powershell/docker/Dockerfile-mariner-2 at main · Azure/azure-powershell · GitHub. It uses the tdnf command to install tar so we can do the same.

tdnf install tar

Windows Observations

Other than the machine name, WSL’s Ubuntu 22.04.2 LTS has the same uname -a output as the docker container from the test image created above (on my x64 Windows 11 machine): Linux 9a13d5e98075 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux.