Skip to content

Instantly share code, notes, and snippets.

@hardyscc
Last active November 2, 2023 04:20
Show Gist options
  • Save hardyscc/bce51d1a458a4640e2e1b999c749da74 to your computer and use it in GitHub Desktop.
Save hardyscc/bce51d1a458a4640e2e1b999c749da74 to your computer and use it in GitHub Desktop.
Docker on Windows

Docker on Windows

Ubuntu on WSL

First make sure uninstall all of the old Ubuntu installation under App & Features.

Install Windows Subsystem for Linux under App & Features > Optional features > More Windows features, then

wsl --update
wsl --set-default-version 2
wsl --install Ubuntu

Under Ubuntu terminal, create your root account then

Add proxy for apt

cat << EOF | sudo tee -a /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://myproxy.com:8080/";
EOF

Add proxy for curl

cat << EOF | sudo tee -a /etc/profile.d/http-proxy.sh
export http_proxy="http://myproxy.com:8080/"
export https_proxy="http://myproxy.com:8080/"
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
EOF

Install docker

sudo apt update
sudo apt install docker.io -y

Add proxy for docker

sudo mkdir /etc/systemd/system/docker.service.d
cat << EOF | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://myproxy.com:8080/"
Environment="HTTPS_PROXY=http://myproxy.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,localaddress,.localdomain.com"
EOF

Add insecure registry

cat << EOF | sudo tee -a /etc/docker/daemon.json
{
  "insecure-registries" : [ "myregistry.com:5000" ]
}
EOF

Add config for registry

cat << EOF | sudo tee -a /etc/profile.d/registry.sh
export REGISTRY_USER=xxxx
export REGISTRY_TOKEN=xxxx
EOF

Restart docker

sudo service docker restart

Use docker

Allow local user to run docker without sudo

sudo usermod -aG docker $USER
sudo chown root:docker /var/run/docker.sock
exit

Open a Command Prompt then run wsl, you can now use docker as normal.

Install kubectl

sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt update
sudo apt install -y kubectl

cat << EOF | sudo tee -a /etc/profile.d/kubectl.sh
alias k='kubectl'
alias kn='kubectl config set-context --current --namespace '
alias kc='kubectl config use-context '
EOF

Install kind

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

Create Cluster

cat << EOF >> cluster-config.yml
# cluster-config.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30000
    hostPort: 30000
    protocol: TCP
EOF

kind create cluster --config=cluster-config.yml

https://kind.sigs.k8s.io/docs/user/using-wsl2/

Teardown

wsl --shutdown
wsl --unregistry Ubuntu

Podman on WSL

First install Windows Subsystem for Linux, then

choco install podman-cli podman-desktop -y

Add insecure registry

Open Podman Desktop then Goto Settings > Registries > Add registry

  • Location: myregistry.com:5000

Ssh into podman machine

podman machine ssh
> sudo vi /etc/containers/registries.conf

then append the following to the end of file

[[registry]]
location = "myregistry.com:5000"
insecure = true

finally restart the podman machine

podman machine stop
podman machine start

You can now use podman to replace docker.

Teardown

podman machine stop
podman machine rm
choco uninstall podman-cli podman-desktop -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment