Build Dockerfile without daemon on Windows

249 views Asked by At

Is there any tool available on Windows which supports building images from Dockerfile (Windows images), which does not require having running daemon on VM?

Seen Buildah and Podman, but from docs it seems they're limited to Linux platform.

3

There are 3 answers

1
rhatdan On

If you want to build linux containers you need a linux kernel. So this requires a VM or a wsl2.

Buildah and Podman should work fine in either case.

0
VonC On

which does not require having running daemon on VM?

podman 4.0.0 (and latest releases like 4.0.2) from Feb. 2022. now comes with:

  • Windows client support (podman.exe)
  • a new VM type, wsl, which uses WSL as a backend for podman machine, instead of creating a separate VM and managing it via QEMU.
  • a minimal requirement for Windows 10 Build 19041 or later

See PR 12503

Introduce Windows WSL implementation of podman machine

This backend maps each machine instance to a WSL distribution.

While this is similar to a virtualized guest utilized by the qemu backend there are a number of architectural differences.

  • Namely, a WSL distribution is essentially a privileged container running under a shared singular WSL Linux kernel covering all other distributions associated with a Windows user.
  • Additionally WSL shares resources with the host Windows OS, so a typical partitioned virtual system config is not utilized.

While the architecture adds restrictions, the approach offers increased performance and improved interoperability over a classic windows virtualization setup.

As an example of the latter, network and filesystem integration are provided by default to all WSL distributions.

Something like:

podman system connection add wsl --identity C:\Users\<my_username>\.ssh\id_rsa_localhost \
                             ssh://<my_username>@localhost/mnt/wslg/runtime-dir/podman/podman.sock
0
whai On

If you are concerned about security issues with demon working in the root context Podman should be your friend now. You need to install WSL2 with Linux image behind (like Ubuntu) bwt.

Please find the blog article: Replace Docker for Windows with Podman that describes the Podman/WSL2 integration in details.

I've let myself compile the case into the single bash podman-quick.sh script. Get it free and execute it on your new WSL2 instance to feel the essence.

#!/bin/bash
export NAME=xUbuntu
export VERSION_ID=20.04
export BASEPATH=/run/user/podman
export PID_FILE=$BASEPATH/podman.pid
export SOCK_FILE=$BASEPATH/podman.sock

#--- Load dependencies
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${NAME}_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${NAME}_${VERSION_ID}/Release.key" | sudo apt-key add -
sudo apt-get update -qq
sudo apt-get -qq -y install podman docker-compose
sudo mkdir -p /etc/containers
sudo mkdir -p $BASEPATH
echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf
alias docker=podman

podman system service --time=0 unix://$SOCK_FILE &  echo "$!" > $PID_FILE
until [[ -S "$SOCK_FILE" && $COUNTER -lt 0 ]]; do echo Wating $COUNTER &&  sleep 1 &&  COUNTER=$((COUNTER-1)); done
if [ -S $SOCK_FILE ]; then  sudo ln -sf $SOCK_FILE /var/run/docker.sock; fi
echo "podman service started, pid is $(cat $PID_FILE)"

# Validate Podman
docker run -dt -p 8080:80/tcp docker.io/library/httpd
curl http://localhost:8080 #... expected: <html><body><h1>It works!</h1></body></html>

# Validate Docker-compose
echo -e "version: '3' \nservices:\n  myalpine:\n    image: python:3.7-alpine" > docker-compose.yml
sudo docker-compose up
sudo docker-compose images #... expected: Image to be resent 'docker.io/library/python'