Docker: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 122: Line 122:
| valign="top" |
| valign="top" |
<source lang="bash">
<source 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 cat /etc/resolv.conf
docker run --rm --net=host busybox nslookup google.com
docker run --rm --net=host alpine nslookup google.com
docker run --rm --net=host alpine nslookup google.com
docker run --rm --net=host alpine ping google.com
docker run --rm --net=host alpine ping google.com
Line 134: Line 134:
| valign="top" |
| valign="top" |
<source lang="bash">
<source lang="bash">
docker run --rm busybox nslookup google.com
docker run --rm alpine cat /etc/resolv.conf
docker run --rm alpine cat /etc/resolv.conf
docker run --rm busybox nslookup google.com
docker run --rm alpine nslookup google.com
docker run --rm alpine nslookup google.com
docker run --rm alpine ping google.com
docker run --rm alpine ping google.com

Revision as of 01:00, 17 September 2020

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

iptables -t nat -S
apt install -y iputils
docker run --rm --detach \
--publish 1983:80 \
--name nginx \
nginx:1.19.2
docker run --rm --detach \
--publish 1983:80 \
--network ckn.b01 \
--ip 10.20.13.20 \
--name nginx \
nginx:1.19.2

Bridge

docker network create \
--driver bridge \
--gateway  10.20.13.1 \
--subnet   10.20.13.0/24 \
--ip-range 10.20.13.16/28 \
--opt com.docker.network.driver.mtu=1500 \
--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.host_binding_ipv4=0.0.0.0 \
--opt com.docker.network.bridge.name=ckn.b01 ckn.b01
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

MAC VLAN

Bridge mode

docker network create \
--driver macvlan \
--gateway  10.19.83.1 \
--subnet   10.19.83.0/24 \
--ip-range 10.19.83.240/28 \
--opt parent=wlan0 ckn.v01

802.1q trunk bridge mode

docker network create \
--driver macvlan \
--gateway  10.19.83.1 \
--subnet   10.19.83.0/24 \
--ip-range 10.19.83.240/28 \
--opt parent=wlan0.01 ckn.v01
docker network inspect ckn.v01
docker network connect ckn.v01 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.19.83.240:1983
curl -v http://localhost:1983
curl -v http://10.19.83.240
docker network disconnect bridge nginx
docker network disconnect ckn.v01 nginx

IP VLAN

docker network create -d ipvlan \
--subnet=10.19.83.0/24 \
--subnet=10.20.13.0/24 \
--gateway=10.19.83.254 \
--gateway=10.20.13.254 \
--opt ipvlan_mode=l2 ckn.i01

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
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
systemctl start docker

Knowledge

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 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 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

Reference