Docker on Windows: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
 
(42 intermediate revisions by the same user not shown)
Line 1: Line 1:
AMD Ryzen 9 3900x, Ryzen 7 5800H supports virtualization. Almost every processors released since a long time have Virtualization. For Windows it's Vt-x, SVM(in some AMD motherboard vtx is renamed as SVM) or AMD-V.
AMD '''Ryzen 9 3900x''', '''Ryzen 7 5800H''' supports virtualization. Almost every processors released since a long time have Virtualization. For Windows it's '''VT-x''', '''SVM'''(in some AMD motherboard vtx is renamed as SVM), '''Vanderpool''' or '''AMD-V'''.


  '''PowerShell run as administrator'''
==PowerShell==
  '''run as administrator'''
  1. Press '''⊞ + R'''
  1. Press '''⊞ + R'''
  2. Type in '''PowerShell'''
  2. Type in '''PowerShell'''
  3. Press '''Control + Shift + Enter'''
  3. Press '''Ctrl + Shift + Enter'''
  4. Choose '''Yes''' Press '''Enter'''
  4. Choose '''Yes''' and Press '''Enter'''
 
<source lang="powershell">
# powershell
net start com.docker.service
net stop  com.docker.service
</source>


==Windows 10 Home==
==Windows 10 Home==
Line 51: Line 58:
             "defaultKeepStorage": "20GB"
             "defaultKeepStorage": "20GB"
         }
         }
     },
     }
    "data-root": "D:\\var\\lib\\docker"
}
}
EOF
EOF
Line 128: Line 134:
Windows: C:\ProgramData\DockerDesktop
Windows: C:\ProgramData\DockerDesktop
MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/
MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/
</source>
<source lang="powershell">
wsl -l -v
wsl -d docker-desktop
wsl -d docker-desktop-data
</source>
==Backup Docker==
<source lang="powershell">
New-Item D:\var\lib\docker -Type Directory -Force
Set-Location -Path D:\var\lib\docker
wsl --export docker-desktop docker_engine.tar
wsl --export docker-desktop-data docker_images.tar
</source>
===Move Engine Path===
<source lang="powershell">
wsl --shutdown
wsl --unregister docker-desktop
Set-Location -Path D:\var\lib\docker
New-Item D:\var\lib\docker\engine -Type Directory -Force
wsl --import docker-desktop  D:\var\lib\docker\engine docker_engine.tar --version 2
Set-Location -Path D:\var\lib\docker\engine
Get-ChildItem
wsl -l -v
net stop com.docker.service
net start com.docker.service
</source>
===Move Images Path===
<source lang="powershell">
wsl --shutdown
wsl --unregister docker-desktop-data
Set-Location -Path D:\var\lib\docker
New-Item D:\var\lib\docker\images -Type Directory -Force
wsl --import docker-desktop-data D:\var\lib\docker\images docker_images.tar --version 2
Set-Location -Path D:\var\lib\docker\images
Get-ChildItem
wsl -l -v
net stop com.docker.service
net start com.docker.service
</source>
===Move Ubuntu Path===
You can move your '''Ubuntu''' distro to elsewhere as following. The drawback is it will be login <code>root</code> user by default. It's lost the integrity, consistency and other features. If you are aware about the risk then now worries else leave it as usual. It's recommended don't make changes or any engineering over there. Leave it as it's. Following example for experimental purpose nothing else.
<source lang="powershell">
New-Item D:\var\wsl\ubuntu -Type Directory -Force
Set-Location -Path D:\var\wsl\ubuntu
wsl --export ubuntu ubuntu.tar
wsl --shutdown
wsl --unregister ubuntu
wsl --import ubuntu D:\var\wsl\ubuntu ubuntu.tar --version 2
Get-ChildItem
wsl -l -v
net stop com.docker.service
net start com.docker.service
</source>
</source>


==Knowledge==
==Knowledge==
<source lang="powershell">
wslconfig /l
wslconfig /u 'Ubuntu'
wslconfig /u 'Ubuntu-18.04'
</source>
<source lang="bash">
<source lang="bash">
docker network ls
docker network ls
Line 144: Line 221:
none --name alpine alpine:latest ash;\
none --name alpine alpine:latest ash;\
docker exec -it alpine ip link show
docker exec -it alpine ip link show
</source>
<source lang="bash">
docker network create --driver bridge \
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00
</source>
</source>


Line 165: Line 237:


<source lang="bash">
<source lang="bash">
docker network disconnect bridge nginx
if [[ "$(</proc/sys/kernel/osrelease)" == *microsoft* ]];then echo 'WSL enabled';fi
docker network disconnect ckn.b00 nginx
if grep -qEi '(Microsoft|WSL)' /proc/version &>/dev/null;then echo 'WSL enabled';fi
docker exec -it nginx ls -lah /sys/class/net/
if [[ "$(</proc/version)" == *microsoft* ]];then echo 'WSL enabled';fi
</source>
 
<source lang="bash">
docker run -itd --network=ckn.b00 nginx
docker network disconnect ckn.b00 nginx
docker network connect --alias db --alias mysql ckn.b00 mysql
</source>
</source>


Line 189: Line 255:
{|
{|
| valign="top" |
| valign="top" |
* [https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl Installing Docker Compose on Raspberry Pi 4]
* [https://www.docker.com/blog/new-docker-desktop-wsl2-backend/ Introducing the Docker Desktop WSL 2 Backend]
* [https://serverfault.com/questions/975980/ Move Docker images to other drive in Windows]
* [https://docs.docker.com/docker-for-windows/install-windows-home Install Docker Desktop on Windows Home]
* [https://docs.docker.com/docker-for-windows/install-windows-home Install Docker Desktop on Windows Home]
* [https://docs.microsoft.com/en-us/windows/wsl/install-win10 Windows Subsystem for Linux Installation]
* [https://docs.microsoft.com/en-us/windows/wsl/install-win10 Windows Subsystem for Linux Installation]
Line 195: Line 262:
* [https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel Updating the WSL-2 Linux kernel]
* [https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel Updating the WSL-2 Linux kernel]
* [https://docs.docker.com/docker-for-windows/wsl/ Docker Desktop WSL-2 backend]
* [https://docs.docker.com/docker-for-windows/wsl/ Docker Desktop WSL-2 backend]
* [[Install Docker in Raspberry Pi 4]]
* [https://docs.microsoft.com/en-us/virtualization/windowscontainers/container-networking/architecture Windows container networking]
* [https://hub.docker.com/editions/community/docker-ce-desktop-windows/ Docker Desktop for Windows]
* [https://hub.docker.com/editions/community/docker-ce-desktop-windows/ Docker Desktop for Windows]
* [https://docs.microsoft.com/en-us/windows/wsl/compare-versions Comparing WSL-1 vs WSL-2]
* [https://docs.microsoft.com/en-us/windows/wsl/compare-versions Comparing WSL-1 vs WSL-2]
* [[Bitbucket Pipelines]]
| valign="top" |
* [[Build Kerberos Docker Image from Ubuntu]]
* [[Build Apache Docker Image from Alpine]]
* [[Build LDAP Docker Image from Ubuntu]]
* [[Build Java Docker Image from CentOS]]
* [[Build Java Docker Image from Ubuntu]]
* [[Docker Run Oracle DB 18c XE]]
* [[Artifactory]]
* [[Jenkins]]
* [[GitLab]]
* [[Nexus]]
| valign="top" |
* [https://stackoverflow.com/questions/48051970 Unable to connect outside from Docker container]
* [https://stackoverflow.com/questions/63572071 Docker published ports are not reachable]
* [https://www.slideshare.net/SreenivasMakam/docker-networking-common-issues-and-troubleshooting-techniques Docker Network Troubleshooting]
* [https://developer.ibm.com/recipes/tutorials/networking-your-docker-containers-using-docker0-bridge Purpose of <code>docker0</code> interface]
* [https://forums.centos.org/viewtopic.php?t=61634 Purpose of <code>virbr0</code> interface]
* [https://superuser.com/questions/995373 Remove <code>docker0</code> bridge]
* [https://docs.docker.com/engine/reference/builder/ Dockerfile Reference]
* [https://www.calculator.net/ip-subnet-calculator.html?cclass=any&csubnet=28&cip=10.19.83.1&ctype=ipv4&printit=0&x=81&y=28 <code>10.19.83.0/28</code>]
* [https://www.calculator.net/ip-subnet-calculator.html?cclass=any&csubnet=28&cip=10.20.13.1&ctype=ipv4&printit=0&x=81&y=15 <code>10.20.13.0/28</code>]
* [https://docs.docker.com/engine/reference/commandline/network/ Docker Network]
|}
----
{|
| valign="top" |
* [https://www.freecodecamp.org/news/how-to-get-a-docker-container-ip-address-explained-with-examples/ How to Get A Docker Container IP Address]
* [https://www.docker.com/blog/understanding-docker-networking-drivers-use-cases/ Docker Networking Drivers and their usage]
* [https://forums.docker.com/t/unable-to-ping-container-from-host/46609 Unable to ping container from host]
* [https://github.com/moby/moby/issues/36151 Containers cannot access Internet]
* [https://docs.microsoft.com/en-us/virtualization/windowscontainers/container-networking/architecture Windows container networking]
* [https://wiki.debian.org/Uncomplicated%20Firewall%20%28ufw%29 Uncomplicated Firewall (<code>ufw</code>)]
* [https://medium.com/@havloujian.joachim/advanced-docker-networking-outgoing-ip-921fc3090b09 Advanced Docker Networking]
* [https://sreeninet.wordpress.com/2016/05/29/macvlan-and-ipvlan/ Macvlan & IPvlan basics]
* [https://docs.docker.com/network/#network-drivers Docker Network drivers]
* [https://hicu.be/macvlan-vs-ipvlan Macvlan vs IPvlan]
| valign="top" |
* [https://stackoverflow.com/questions/42158596/can-windows-containers-be-hosted-on-linux#:~:text=solution%20which%20uses%20Vagrant%20and%20Packer%20on%20Mac Can Windows Containers be hosted on Linux?]
* [https://forums.docker.com/t/network-bridge-docker0-cant-connect-to-local-network/78175/17#:~:text=default-address-pools <code>Docker0</code> can’t connect to Local Network]
* [https://docs.docker.com/registry/recipes/mirror/#run-a-registry-as-a-pull-through-cache Run a Registry as a pull-through Cache]
* [https://docs.docker.com/network/bridge/#configure-the-default-bridge-network Customize the <code>docker0</code> bridge]
* [https://github.com/docker-library/postgres PostgreSQL Docker Community]
* [https://docs.docker.com/docker-for-mac/apple-m1/ Docker Apple M1 Tech Preview]
* [https://github.com/docker-library/openjdk OpenJDK Docker Community]
* [https://github.com/docker-library/python Python Docker Community]
* [https://hub.docker.com/r/arm32v6/postgres/ PostgreSQL <code>arm32v6</code>]
* [https://itnext.io/docker-in-docker-521958d34efd Docker in Docker]


| valign="top" |
| valign="top" |
Line 263: Line 278:
* [https://kafka.apache.org/ Apache Kafka]
* [https://kafka.apache.org/ Apache Kafka]


|}
----
{|
| valign="top" |
| valign="top" |
* [https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon Configure Docker <code>daemon.json</code> on Windows]
* [https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon Configure Docker <code>daemon.json</code> on Windows]
* [https://stackoverflow.com/questions/61396989/ What is the <code>docker-desktop-data</code> distro?]
* [https://superuser.com/questions/1317883/ Uninstall the subsystem for Linux on Windows]
* [https://blog.frankfu.com.au/2018/03/09/change-dockers-default-storage-directory-for-images/ Docker change default containers directory]
* [https://blog.frankfu.com.au/2018/03/09/change-dockers-default-storage-directory-for-images/ Docker change default containers directory]
* [https://logging.apache.org/log4j/2.x/manual/cloud.html Using Log4j in Cloud Enabled Applications]
* [https://logging.apache.org/log4j/2.x/manual/cloud.html Using Log4j in Cloud Enabled Applications]
* [https://docs.docker.com/docker-for-windows/troubleshoot/#virtualization Docker for Windows Troubleshooting]
* [https://docs.microsoft.com/en-us/windows/wsl/wsl-config WSL commands and launch config]
* [https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0383441 Copy files to/from a container]
* [https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0383441 Copy files to/from a container]
* [[Docker Compose]]
* [[Docker]]
|-
| colspan="3" |
----
|-
| valign="top" |
* [https://www.google.com/search?q=enable+virtualization+in+bios+%2B+American+Megatrends Enable Virtualization in BIOS + American Megatrends]
* [https://docs.microsoft.com/en-us/windows/wsl/use-custom-distro WSL use a custom Linux distribution]
* [https://stackoverflow.com/questions/37599128/ Disable auto-restart of a container]
* [https://docs.microsoft.com/en-us/windows/wsl/wsl2-mount-disk Mounting a Linux disk in WSL 2]
* [https://docs.chocolatey.org/en-us/choco/commands/uninstall Chocolatey Uninstall Package]
* [https://stackoverflow.com/questions/38086185/ Detect WSL vs Native Linux]
* [https://stackoverflow.com/questions/38859145/ Trace WSL vs Native Linux]
* [[Linux Containers]]


| valign="top" |
| valign="top" |


|}
|}

Latest revision as of 22:35, 21 November 2021

AMD Ryzen 9 3900x, Ryzen 7 5800H supports virtualization. Almost every processors released since a long time have Virtualization. For Windows it's VT-x, SVM(in some AMD motherboard vtx is renamed as SVM), Vanderpool or AMD-V.

PowerShell

run as administrator
1. Press ⊞ + R
2. Type in PowerShell
3. Press Ctrl + Shift + Enter
4. Choose Yes and Press Enter
# powershell
net start com.docker.service
net stop  com.docker.service

Windows 10 Home

# powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2
# powershell
docker pull hello-world
docker run -it --rm --name hello hello-world:latest
# gitbash
winpty docker pull hello-world
winpty docker run -it --rm --name hello hello-world:latest

Networking

cat <<EOF > /mnt/c/Users/shahed/.docker/daemon.json
{
    "bip": "10.20.13.1/24",
    "mtu": 1500,
    "dns": [
        "10.19.83.100",
        "10.19.83.1"
    ],
    "registry-mirrors": [],
    "insecure-registries": [],
    "debug": true,
    "experimental": false,
    "features": {
        "buildkit": true
    },
    "builder": {
        "gc": {
            "enabled": true,
            "defaultKeepStorage": "20GB"
        }
    }
}
EOF
cat <<EOF > /mnt/c/Users/shahed/.docker/daemon.json
{
    "mtu": 1500,
    "debug": true,
    "experimental": false,
    "default-address-pools": [
        {
            "base": "10.20.0.0/16",
            "size": 24
        }
    ]
}
EOF
docker run --rm --detach --publish 1983:80 nginx
docker run --rm --detach --net=host nginx

docker run --rm --detach --publish 1983:80 --net=ckn.b00 --ip 10.20.15.10 nginx
docker run --rm --detach --publish 1983:80 --net=ckn.b01 --ip 10.20.16.10 nginx

Cache or Mirror

mkdir -p /etc/docker/registry
cat <<EOF > /etc/docker/registry/config.yml
proxy:
  remoteurl: https://hub.chorke.org
  username: academia
  password: sadaqah!
EOF

Troubleshoot

docker run --rm --net=host busybox nslookup google.com
docker run --rm --net=host alpine cat /etc/resolv.conf
docker run --rm --net=host alpine nslookup google.com
docker run --rm --net=host alpine ping google.com
docker run --rm --net=host alpine cat /etc/hosts
docker run --rm --net=host alpine ifconfig
docker run --rm --net=host alpine ip addr
docker run --rm --net=host alpine route
docker run --rm busybox nslookup google.com
docker run --rm alpine cat /etc/resolv.conf
docker run --rm alpine nslookup google.com
docker run --rm alpine ping google.com
docker run --rm alpine cat /etc/hosts
docker run --rm alpine ifconfig
docker run --rm alpine ip addr
docker run --rm alpine route

Images Path

Ubuntu: /var/lib/docker/
Fedora: /var/lib/docker/
Debian: /var/lib/docker/
Windows: C:\ProgramData\DockerDesktop
MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/
wsl -l -v
wsl -d docker-desktop
wsl -d docker-desktop-data

Backup Docker

New-Item D:\var\lib\docker -Type Directory -Force
Set-Location -Path D:\var\lib\docker

wsl --export docker-desktop docker_engine.tar
wsl --export docker-desktop-data docker_images.tar

Move Engine Path

wsl --shutdown
wsl --unregister docker-desktop
Set-Location -Path D:\var\lib\docker

New-Item D:\var\lib\docker\engine -Type Directory -Force
wsl --import docker-desktop  D:\var\lib\docker\engine docker_engine.tar --version 2
Set-Location -Path D:\var\lib\docker\engine
Get-ChildItem

wsl -l -v
net stop com.docker.service
net start com.docker.service

Move Images Path

wsl --shutdown
wsl --unregister docker-desktop-data
Set-Location -Path D:\var\lib\docker

New-Item D:\var\lib\docker\images -Type Directory -Force
wsl --import docker-desktop-data D:\var\lib\docker\images docker_images.tar --version 2
Set-Location -Path D:\var\lib\docker\images
Get-ChildItem

wsl -l -v
net stop com.docker.service
net start com.docker.service

Move Ubuntu Path

You can move your Ubuntu distro to elsewhere as following. The drawback is it will be login root user by default. It's lost the integrity, consistency and other features. If you are aware about the risk then now worries else leave it as usual. It's recommended don't make changes or any engineering over there. Leave it as it's. Following example for experimental purpose nothing else.

New-Item D:\var\wsl\ubuntu -Type Directory -Force
Set-Location -Path D:\var\wsl\ubuntu
wsl --export ubuntu ubuntu.tar

wsl --shutdown
wsl --unregister ubuntu
wsl --import ubuntu D:\var\wsl\ubuntu ubuntu.tar --version 2
Get-ChildItem

wsl -l -v
net stop com.docker.service
net start com.docker.service

Knowledge

wslconfig /l
wslconfig /u 'Ubuntu'
wslconfig /u 'Ubuntu-18.04'
docker network ls
docker network prune
docker network rm ckn.b00 ckn.b01

docker inspect nginx|grep "IPAddress"
docker network inspect bridge|grep "Gateway"
docker run --rm -dit --network \
none --name alpine alpine:latest ash;\
docker exec -it alpine ip link show
docker network connect ckn.b00 nginx
docker exec -it nginx cat /etc/hosts
docker inspect nginx|grep "IPAddress"
docker exec -it nginx cat /etc/resolv.conf
docker exec -it nginx ls -lah /sys/class/net/
docker cp ~/.m2/settings.xml alpine:~/.m2/settings.xml
docker cp alpine:~/.m2/settings.xml ~/.m2/settings.xml
if [[ "$(</proc/sys/kernel/osrelease)" == *microsoft* ]];then echo 'WSL enabled';fi
if grep -qEi '(Microsoft|WSL)' /proc/version &>/dev/null;then echo 'WSL enabled';fi
if [[ "$(</proc/version)" == *microsoft* ]];then echo 'WSL enabled';fi
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
docker ps --format "table {{.ID}}\t{{.Labels}}"
docker ps --format '{{.Names}}\t{{.Image}}'
docker ps --format "{{.ID}}: {{.Command}}"
docker ps --filter publish=80/udp

Reference