Docker: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(127 intermediate revisions by the same user not shown)
Line 1: Line 1:
{|class='wikitable' style='width:100%;margin:-11px 0 6px 0'
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
sudo usermod -aG docker $USER
newgrp docker
mkdir "$HOME/.docker"
sudo chown "$USER":"$USER" "$HOME/.docker" -R
sudo chmod g+rwx "$HOME/.docker" -R
sudo systemctl daemon-reload
sudo systemctl restart docker.service
</syntaxhighlight>
|}
==Windows 10 Home==
==Windows 10 Home==
<source lang="powershell">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Windows 10 Home
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='powershell'>
# powershell
# powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2
wsl --set-default-version 2
</source>
</syntaxhighlight>
 
|-
<source lang="powershell">
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='powershell'>
# powershell
# powershell
docker pull hello-world
docker pull hello-world
docker run -it --rm --name hello hello-world:latest
docker run -it --rm --name hello hello-world:latest
</source>
</syntaxhighlight>


<source lang="bash">
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# gitbash
# gitbash
winpty docker pull hello-world
winpty docker pull hello-world
winpty docker run -it --rm --name hello hello-world:latest
winpty docker run -it --rm --name hello hello-world:latest
</source>
</syntaxhighlight>
|}


==Networking==
==Networking==
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
docker run --rm --detach \
!scope='col' style='text-align:left' colspan='2'|
--publish 1983:80 \
Networking
--name nginx \
|-
nginx:1.19.2
|valign='top' style='width:50%'|
</source>
<syntaxhighlight style='margin:3px 0' lang='json'>
cat <<'EOF' | \
sudo tee /etc/docker/daemon.json >/dev/null
{
    "bip"  : "10.20.13.1/24",
    "mtu"  : 1500,
    "dns"  : [
        "1.1.1.1",
        "8.8.8.8",
        "192.168.49.2"
    ],
    "debug": true
}
EOF
</syntaxhighlight>
 
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='json'>
cat << EOF | \
sudo tee /etc/docker/daemon.json >/dev/null
{
    "mtu"   : 1500,
    "debug" : true,
    "experimental": false,
    "default-address-pools" :[{
        "base"  : "10.20.0.0/16",
        "size"  : 24
    }]
}
 
EOF
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
apt install -y iputils
iptables -t nat -S
 
service docker stop
service docker start
 
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
</syntaxhighlight>
 
|valign='top'|
|}


===Bridge===
===Bridge===
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Bridge
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network create \
docker network create \
--driver bridge \
--driver bridge \
--gateway  10.20.13.1 \
--gateway  10.20.15.1 \
--subnet  10.20.13.0/24 \
--subnet  10.20.15.0/24 \
--ip-range 10.20.13.16/28 \
--opt com.docker.network.driver.mtu=1500 \
--opt com.docker.network.driver.mtu=1500 \
--opt com.docker.network.bridge.enable_icc=true \
--opt com.docker.network.bridge.enable_icc=true \
--opt com.docker.network.bridge.default_bridge=false \
--opt com.docker.network.bridge.enable_ip_masquerade=true \
--opt com.docker.network.bridge.enable_ip_masquerade=true \
--opt com.docker.network.bridge.host_binding_ipv4=0.0.0.0 \
--opt com.docker.network.bridge.host_binding_ipv4=0.0.0.0 \
--opt com.docker.network.bridge.name=ckn.b01 ckn.b01
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00
</source>
</syntaxhighlight>
 
|}
<source lang="bash">
docker network create --subnet 10.20.13.32/28 --gateway=10.20.13.33 ckn.b02
docker network create --subnet 10.20.13.48/28 --gateway=10.20.13.49 ckn.b03
docker network create --subnet 10.20.13.64/28 --gateway=10.20.13.65 ckn.b04
docker network create --subnet 10.20.13.80/28 --gateway=10.20.13.81 ckn.b05
</source>
----


===MAC VLAN===
===MAC VLAN===
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
MAC VLAN
|-
|valign='top'|
'''Bridge mode'''
'''Bridge mode'''
<source lang="bash">
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network create \
docker network create \
--driver macvlan \
--driver macvlan \
--gateway  10.19.83.1 \
--gateway  10.20.20.1 \
--subnet  10.19.83.0/24 \
--subnet  10.20.20.0/24 \
--ip-range 10.19.83.240/28 \
--opt parent=wlan0 ckn.v00
--opt parent=wlan0 ckn.v01
</syntaxhighlight>
</source>
|-
 
|valign='top'|
'''802.1q trunk bridge mode'''
'''802.1q trunk bridge mode'''
<source lang="bash">
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network create \
docker network create \
--driver macvlan \
--driver macvlan \
--gateway  10.19.83.1 \
--gateway  10.20.20.1 \
--subnet  10.19.83.0/24 \
--subnet  10.20.20.0/24 \
--ip-range 10.19.83.240/28 \
--ip-range 10.20.20.240/28 \
--opt parent=wlan0.01 ckn.v01
--opt parent=wlan0.01 ckn.v01
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top'|
docker network inspect ckn.v01
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network connect ckn.v01 nginx
docker network inspect ckn.v00
</source>
docker network connect ckn.v00 nginx
 
</syntaxhighlight>
<source lang="bash">
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker exec -it nginx ls -lah /sys/class/net/
docker exec -it nginx ls -lah /sys/class/net/
docker exec -it nginx cat /etc/resolv.conf
docker inspect nginx|grep "IPAddress"
docker inspect nginx|grep "IPAddress"
docker exec -it nginx cat /etc/hosts


curl -v http://10.19.83.240:1983
curl -v http://10.20.20.240:1983
curl -v http://localhost:1983
curl -v http://localhost:1983
curl -v http://10.19.83.240
curl -v http://10.20.20.240
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network disconnect bridge nginx
docker network disconnect bridge nginx
docker network disconnect ckn.v01 nginx
docker network disconnect ckn.v00 nginx
</source>
</syntaxhighlight>
|}


----
===IP VLAN===
===IP VLAN===
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
IP VLAN
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network create -d ipvlan \
docker network create -d ipvlan \
--subnet=10.19.83.0/24 \
--subnet=10.20.1.0/24 \
--subnet=10.20.13.0/24 \
--subnet=10.20.2.0/24 \
--gateway=10.19.83.254 \
--gateway=10.20.1.254 \
--gateway=10.20.13.254 \
--gateway=10.20.2.254 \
--opt ipvlan_mode=l2 ckn.i01
--opt ipvlan_mode=l2 ckn.i00
</source>
</syntaxhighlight>
|}
 
==Cache or Mirror==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Cache or Mirro
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='yaml'>
mkdir -p /etc/docker/registry
cat <<EOF > /etc/docker/registry/config.yml
---
proxy:
  remoteurl: https://hub.chorke.org
  username: academia
  password: sadaqah!
EOF
</syntaxhighlight>
|}
 
==Add Tag & Push==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Add Tag & Push
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
RFIND_FILL="s|docker.chorke.com|docker.chorke.org|";\
OLD_IMAGES="$(docker images --format 'table {{.Repository}}:{{.Tag}}'|grep chorke)";\
for OLD_IMAGE in ${OLD_IMAGES};do\
    NEW_IMAGE="$(echo ${OLD_IMAGE}|sed ${RFIND_FILL})";\
    docker tag  ${OLD_IMAGE} ${NEW_IMAGE} &&\
    docker push ${NEW_IMAGE} &&\
    docker rmi  ${NEW_IMAGE} &&\
    docker rmi  ${OLD_IMAGE};\
done
</syntaxhighlight>
|}
 
==Troubleshoot==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Troubleshoot
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
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
</syntaxhighlight>
 
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
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
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker run --add-host=host.docker.internal:host-gateway\
-it --rm alpine ping host.docker.internal
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker run --add-host=host.docker.internal:host-gateway\
-it --rm alpine sh
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker inspect crawler|grep compose
docker logs    crawler
docker logs -f crawler
</syntaxhighlight>
 
|valign='top'|
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
export DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --iptables=false --ip-forward=false"
firewall-cmd --permanent --zone=trusted --change-interface=docker0
firewall-cmd --reload
systemctl restart docker
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
systemctl stop docker
rm -fr /var/lib/docker
rm -fr /etc/docker
pkill docker
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
systemctl start docker
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
vim /etc/selinux/config
shutdown -r now
setenforce 0
sestatus
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
#devil most things for docker0 bridge
sudo apt remove netscript-2.4
sudo apt purge  netscript-2.4
sudo apt autoremove
</syntaxhighlight>
|}
 
==Ryzen AMD-V==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Ryzen AMD-V
|-
|valign='top'|
Yes, AMD Ryzen 9 3900x supports virtualization. Almost every processors released since a long time have Virtualization. For Windows it's Vt-x or SVM(in some AMD motherboard vtx is renamed as SVM).
|}
 
==Images Path==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Images Path
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='properties'>
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/
</syntaxhighlight>
|}
 
==Backup & Restore==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Backup & Restore
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker pull  gitea/gitea:1.10.6
docker pull  gitea/gitea:1.16.2
 
docker image load -i ~/.config/backup/gitea_gitea_1.10.6.tar
docker image load -i ~/.config/backup/gitea_gitea_1.16.2.tar
 
docker image save -o ~/.config/backup/gitea_gitea_1.10.6.tar gitea/gitea:1.10.6
docker image save -o ~/.config/backup/gitea_gitea_1.16.2.tar gitea/gitea:1.16.2
</syntaxhighlight>
|}
 
==Reclaim Disk Space==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Reclaim Disk Space
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
cat <<'EXE' | sudo bash
sh -c 'du -sh /var/lib/docker/containers/*'
sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log' 2>/dev/null
 
docker images -f 'dangling=true' -q
docker rmi $(docker images -f 'dangling=true' -q) 2>/dev/null
 
docker system  prune -f --volumes
docker builder prune -f -a
docker network prune -f
docker volume  prune -f
 
apt-get clean
apt-get autoclean
apt-get autoremove -y
 
journalctl --disk-usage
journalctl --vacuum-time=90d
 
find /tmp -type f -mtime +7
find /tmp -type f -mtime +7 -delete
 
find /var/log/nginx  -type f -mtime +90
find /var/log/nginx  -type f -mtime +90 -delete
EXE
</syntaxhighlight>
|}
 
==Custom Docker Image==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Custom Docker Image
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
cat <<'INI' | tee ./Dockerfile >/dev/null
FROM eclipse-temurin:17-jre-focal
 
RUN apt update --fix-missing \
  && apt install -y nginx apache2-utils
INI
 
docker build --rm -t 'docker.shahed.biz/tools/eclipse-temurin:17-jre-focal' -f ./Dockerfile .
docker push          docker.shahed.biz/tools/eclipse-temurin:17-jre-focal
</syntaxhighlight>
|}
 
==Recovery Parent Image==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Recovery Parent Image
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker pull    docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker history docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker inspect docker.shahed.biz/shahed-academia-apps:2025-10-10T1010 | jq '.[0].RootFS.Layers'
 
docker run -it --name recovery-openjdk-17-slim docker.shahed.biz/shahed-academia-apps:2025-10-10T1010 bash
# executing bash command try to clean up new changes and then commit as below
docker commit recovery-openjdk-17-slim openjdk:17-slim
 
docker run --rm \
  -v /var/run/docker.sock:/var/run/docker.sock \
  alpine/dfimage:1.2    docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
 
docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  wagoodman/dive:v0.13.1 docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
 
docker rmi docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker rm  recovery-openjdk-17-slim
docker rmi wagoodman/dive:v0.13.1
docker rmi alpine/dfimage:1.2
</syntaxhighlight>
|}


==Knowledge==
==Knowledge==
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Knowledge
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network ls
docker network ls
docker network prune
docker network prune
docker network rm ckn.b00 ckn.b01
docker network rm ckn.b00 ckn.b01


docker inspect nginx|grep compose
docker inspect nginx|grep "IPAddress"
docker inspect nginx|grep "IPAddress"
docker network inspect bridge|grep "Gateway"
docker network inspect bridge|grep "Gateway"
</source>
</syntaxhighlight>
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker rm $(docker ps -a -q)
docker stop $(docker ps -a -q)
</syntaxhighlight>


<source lang="bash">
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker inspect nginx
docker update --restart=no nginx
</syntaxhighlight>
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker run --rm -dit --network \
docker run --rm -dit --network \
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>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network create --driver bridge \
docker network create --driver bridge \
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network connect ckn.b00 nginx
docker network connect ckn.b00 nginx
docker exec -it nginx cat /etc/hosts
docker inspect nginx|grep "IPAddress"
docker inspect nginx|grep "IPAddress"
docker exec -it nginx cat /etc/resolv.conf
docker exec -it nginx ls -lah /sys/class/net/
docker exec -it nginx ls -lah /sys/class/net/
</source>
docker run --add-host=host.docker.internal:host-gateway\
 
--rm alpine ping host.docker.internal
<source lang="bash">
</syntaxhighlight>
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker cp ~/.m2/settings.xml alpine:/root/.m2/settings.xml
docker cp alpine:/root/.m2/settings.xml ~/.m2/settings.xml
</syntaxhighlight>
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker network disconnect bridge nginx
docker network disconnect bridge nginx
docker network disconnect ckn.b00 nginx
docker network disconnect ckn.b00 nginx
docker exec -it nginx ls -lah /sys/class/net/
docker exec -it nginx ls -lah /sys/class/net/
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
docker run -itd --network=ckn.b00 nginx
docker run -itd --network=ckn.b00 nginx
docker network disconnect ckn.b00 nginx
docker network disconnect ckn.b00 nginx
docker network connect --alias db --alias mysql ckn.b00 mysql
docker network connect --alias db --alias mysql ckn.b00 mysql
</source>
</syntaxhighlight>
|-
|valign='top' colspan='2'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
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
</syntaxhighlight>
|}


==Reference==
==References==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
| valign="top" |
!scope='col' style='text-align:left' colspan='3'|
References
|-
|valign='top' style='width:33%'|
* [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://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://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]
Line 154: Line 540:
* [[Bitbucket Pipelines]]
* [[Bitbucket Pipelines]]


| valign="top" |
|valign='top' style='width:34%'|
* [[Build Kerberos Docker Image from Ubuntu]]
* [[Build Kerberos Docker Image from Ubuntu]]
* [[Build Apache Docker Image from Alpine]]
* [[Build Apache Docker Image from Alpine]]
Line 166: Line 552:
* [[Nexus]]
* [[Nexus]]


| valign="top" |
|valign='top' style='width:33%'|
* [https://stackoverflow.com/questions/48051970 Unable to connect outside from Docker container]
* [https://stackoverflow.com/questions/48051970 Unable to connect outside from Docker container]
* [https://stackoverflow.com/questions/63572071 Docker published ports are not reachable]
* [https://stackoverflow.com/questions/63572071 Docker published ports are not reachable]
* [https://www.slideshare.net/SreenivasMakam/docker-networking-common-issues-and-troubleshooting-techniques Docker Networking - Common Issues]
* [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://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://forums.centos.org/viewtopic.php?t=61634 Purpose of <code>virbr0</code> interface]
Line 177: Line 563:
* [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://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]
* [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]
{|
| valign="top" |
* [https://www.docker.com/blog/understanding-docker-networking-drivers-use-cases/ Docker Networking Drivers and their usage]
* [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://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://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://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'|
* [https://github.com/StefanScherer/windows-docker-machine Windows Container using Vagrant & Packer on Mac]
* [https://stackoverflow.com/questions/10268583/ Downloading Java JDK on Linux via wget]
* [https://blog.developer.atlassian.com/minimal-java-docker-containers/ Smaller Java images with Alpine Linux]
* [https://hub.packtpub.com/build-java-ee-containers-using-docker-tutorial/ Build Java EE containers using Docker]
* [https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/ Don't use Docker in Docker for CI]
* [https://www.docker.com/blog/how-to-deploy-on-remote-docker-hosts-with-docker-compose/ Docker Compose Remote Deploy]
* [https://www.consul.io/use-cases/service-discovery-and-health-checking Consul Service Discovery]
* [https://doc.traefik.io/traefik/providers/overview/ Traefik Service Discovery]
* [https://flume.apache.org/ Apache Flume]
* [https://kafka.apache.org/ Apache Kafka]
|-
|valign='top'|
* [https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon Configure Docker <code>daemon.json</code> on Windows]
* [https://logging.apache.org/log4j/2.x/manual/cloud.html Using Log4j in Cloud Enabled Applications]
* [https://stackoverflow.com/questions/37599128/ Disable auto-restart of a container]
* [https://docs.docker.com/engine/install/linux-postinstall/ Post-installation steps for Linux]
* [https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0383441 Copy files to/from a container]
* [https://www.freecodecamp.org/news/where-are-docker-images-stored-docker-container-paths-explained/ Docker Images Stored Path]
* [https://docs.docker.com/develop/develop-images/multistage-build/ Docker multi-stage builds]
* [[Docker on Windows]]
* [[Linux Containers]]
* [[Podman]]
|valign='top'|
* [https://devopscube.com/reduce-docker-image-size/ Reduce Docker Image Size: 6 Optimal Methods]
* [https://medium.com/@TimvanBaarsen/how-to-connect-to-the-docker-host-from-inside-a-docker-container-112b4c71bc66  Connect to the Docker host from a Container]
* [https://kool.dev/ Kool standardizes the way you work across]
* [https://docs.docker.com/desktop/mac/apple-silicon/ Docker Desktop for Apple silicon]
* [https://stackoverflow.com/questions/40082608/ Delete interface <code>docker0</code>]
* [https://docs.docker.com/develop/develop-images/multistage-build/ Docker Multi-Stage builds]
* [https://vsupalov.com/docker-arg-vs-env/ Docker ARG vs ENV]
* [[Docker Compose]]
* [[Vagrant]]
* [[Qemu]]
|valign='top'|
* [https://medium.com/@TimvanBaarsen/how-to-connect-to-the-docker-host-from-inside-a-docker-container-112b4c71bc66  Docker » Host » <code>host.docker.internal</code>]
* [https://github.com/pgadmin-org/pgadmin4/blob/master/Dockerfile Alpine » Dockerfile » PgAdmin 4]
* [https://github.com/better/alpine-tensorflow/blob/master/Dockerfile Alpine » Dockerfile » Tensorflow]
* [https://stackoverflow.com/questions/35689628/ Docker » Alpine Shell Access]
* [https://help.ubuntu.com/community/WakeOnLan Setting Up Wake-on-LAN]
* [https://docs.docker.com/engine/reference/commandline/checkpoint/ Docker » Checkpoint]
* [[Java Remote Debug]]
* [[Multipass]]
* [[Proxmox]]
* [[Juju]]
|-
|valign='top'|
* [[Dockerized PostgreSQL|Docker » PostgreSQL]]
|valign='top'|
|valign='top'|


| valign="top" |
|}
|}

Latest revision as of 07:59, 15 January 2026

sudo usermod -aG docker $USER
newgrp docker

mkdir "$HOME/.docker"
sudo chown "$USER":"$USER" "$HOME/.docker" -R
sudo chmod g+rwx "$HOME/.docker" -R

sudo systemctl daemon-reload
sudo systemctl restart docker.service

Windows 10 Home

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

Networking

cat <<'EOF' | \
sudo tee /etc/docker/daemon.json >/dev/null
{
    "bip"  : "10.20.13.1/24",
    "mtu"  : 1500,
    "dns"  : [
        "1.1.1.1",
        "8.8.8.8",
        "192.168.49.2"
    ],
    "debug": true
}
EOF
cat << EOF | \
sudo tee /etc/docker/daemon.json >/dev/null
{
    "mtu"   : 1500,
    "debug" : true,
    "experimental": false,
    "default-address-pools" :[{
        "base"  : "10.20.0.0/16",
        "size"  : 24
    }]
}

EOF
apt install -y iputils
iptables -t nat -S

service docker stop
service docker start

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

Bridge

Bridge

docker network create \
--driver bridge \
--gateway  10.20.15.1 \
--subnet   10.20.15.0/24 \
--opt com.docker.network.driver.mtu=1500 \
--opt com.docker.network.bridge.enable_icc=true \
--opt com.docker.network.bridge.enable_ip_masquerade=true \
--opt com.docker.network.bridge.host_binding_ipv4=0.0.0.0 \
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00

MAC VLAN

MAC VLAN

Bridge mode

docker network create \
--driver macvlan \
--gateway  10.20.20.1 \
--subnet   10.20.20.0/24 \
--opt parent=wlan0 ckn.v00

802.1q trunk bridge mode

docker network create \
--driver macvlan \
--gateway  10.20.20.1 \
--subnet   10.20.20.0/24 \
--ip-range 10.20.20.240/28 \
--opt parent=wlan0.01 ckn.v01
docker network inspect ckn.v00
docker network connect ckn.v00 nginx
docker exec -it nginx ls -lah /sys/class/net/
docker exec -it nginx cat /etc/resolv.conf
docker inspect nginx|grep "IPAddress"
docker exec -it nginx cat /etc/hosts

curl -v http://10.20.20.240:1983
curl -v http://localhost:1983
curl -v http://10.20.20.240
docker network disconnect bridge nginx
docker network disconnect ckn.v00 nginx

IP VLAN

IP VLAN

docker network create -d ipvlan \
--subnet=10.20.1.0/24 \
--subnet=10.20.2.0/24 \
--gateway=10.20.1.254 \
--gateway=10.20.2.254 \
--opt ipvlan_mode=l2 ckn.i00

Cache or Mirror

Cache or Mirro

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

Add Tag & Push

Add Tag & Push

RFIND_FILL="s|docker.chorke.com|docker.chorke.org|";\
OLD_IMAGES="$(docker images --format 'table {{.Repository}}:{{.Tag}}'|grep chorke)";\
for OLD_IMAGE in ${OLD_IMAGES};do\
    NEW_IMAGE="$(echo ${OLD_IMAGE}|sed ${RFIND_FILL})";\
    docker tag  ${OLD_IMAGE} ${NEW_IMAGE} &&\
    docker push ${NEW_IMAGE} &&\
    docker rmi  ${NEW_IMAGE} &&\
    docker rmi  ${OLD_IMAGE};\
done

Troubleshoot

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
docker run --add-host=host.docker.internal:host-gateway\
 -it --rm alpine ping host.docker.internal
docker run --add-host=host.docker.internal:host-gateway\
 -it --rm alpine sh
 docker inspect crawler|grep compose
 docker logs    crawler
 docker logs -f crawler
export DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --iptables=false --ip-forward=false"
firewall-cmd --permanent --zone=trusted --change-interface=docker0
firewall-cmd --reload
systemctl restart docker
systemctl stop docker
rm -fr /var/lib/docker
rm -fr /etc/docker
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
systemctl start docker
vim /etc/selinux/config
shutdown -r now
setenforce 0
sestatus
#devil most things for docker0 bridge
sudo apt remove netscript-2.4
sudo apt purge  netscript-2.4
sudo apt autoremove

Ryzen AMD-V

Ryzen AMD-V

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

Images Path

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/

Backup & Restore

Backup & Restore

docker pull  gitea/gitea:1.10.6
docker pull  gitea/gitea:1.16.2

docker image load -i ~/.config/backup/gitea_gitea_1.10.6.tar
docker image load -i ~/.config/backup/gitea_gitea_1.16.2.tar

docker image save -o ~/.config/backup/gitea_gitea_1.10.6.tar gitea/gitea:1.10.6
docker image save -o ~/.config/backup/gitea_gitea_1.16.2.tar gitea/gitea:1.16.2

Reclaim Disk Space

Reclaim Disk Space

cat <<'EXE' | sudo bash
sh -c 'du -sh /var/lib/docker/containers/*'
sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log' 2>/dev/null

docker images -f 'dangling=true' -q
docker rmi $(docker images -f 'dangling=true' -q) 2>/dev/null

docker system  prune -f --volumes
docker builder prune -f -a
docker network prune -f
docker volume  prune -f

apt-get clean
apt-get autoclean
apt-get autoremove -y

journalctl --disk-usage
journalctl --vacuum-time=90d

find /tmp -type f -mtime +7
find /tmp -type f -mtime +7 -delete

find /var/log/nginx  -type f -mtime +90 
find /var/log/nginx  -type f -mtime +90 -delete
EXE

Custom Docker Image

Custom Docker Image

cat <<'INI' | tee ./Dockerfile >/dev/null
FROM eclipse-temurin:17-jre-focal

RUN apt update --fix-missing \
  && apt install -y nginx apache2-utils
INI

docker build --rm -t 'docker.shahed.biz/tools/eclipse-temurin:17-jre-focal' -f ./Dockerfile .
docker push           docker.shahed.biz/tools/eclipse-temurin:17-jre-focal

Recovery Parent Image

Recovery Parent Image

docker pull    docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker history docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker inspect docker.shahed.biz/shahed-academia-apps:2025-10-10T1010 | jq '.[0].RootFS.Layers'

docker run -it --name recovery-openjdk-17-slim docker.shahed.biz/shahed-academia-apps:2025-10-10T1010 bash
# executing bash command try to clean up new changes and then commit as below
docker commit recovery-openjdk-17-slim openjdk:17-slim

docker run --rm \
  -v /var/run/docker.sock:/var/run/docker.sock \
  alpine/dfimage:1.2     docker.shahed.biz/shahed-academia-apps:2025-10-10T1010

docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  wagoodman/dive:v0.13.1 docker.shahed.biz/shahed-academia-apps:2025-10-10T1010

docker rmi docker.shahed.biz/shahed-academia-apps:2025-10-10T1010
docker rm  recovery-openjdk-17-slim
docker rmi wagoodman/dive:v0.13.1
docker rmi alpine/dfimage:1.2

Knowledge

Knowledge

docker network ls
docker network prune
docker network rm ckn.b00 ckn.b01

docker inspect nginx|grep compose
docker inspect nginx|grep "IPAddress"
docker network inspect bridge|grep "Gateway"
docker rm $(docker ps -a -q)
docker stop $(docker ps -a -q)
docker inspect nginx
docker update --restart=no nginx
docker run --rm -dit --network \
none --name alpine alpine:latest ash;\
docker exec -it alpine ip link show
docker network create --driver bridge \
--opt com.docker.network.bridge.name=ckn.b00 ckn.b00
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 run --add-host=host.docker.internal:host-gateway\
 --rm alpine ping host.docker.internal
docker cp ~/.m2/settings.xml alpine:/root/.m2/settings.xml
docker cp alpine:/root/.m2/settings.xml ~/.m2/settings.xml
docker network disconnect bridge nginx
docker network disconnect ckn.b00 nginx
docker exec -it nginx ls -lah /sys/class/net/
docker run -itd --network=ckn.b00 nginx
docker network disconnect ckn.b00 nginx
docker network connect --alias db --alias mysql ckn.b00 mysql
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

References

References