Hello,
i’m try to install and setup iptables inside a container (zerotier)
i have a container with zerotier that works fine
but i would use iptables inside a container
so i test with
version: '2'
services:
zerotier-one:
image: zerotier/zerotier:latest
container_name: zerotier-one
restart: unless-stopped
cap_add:
- SYS_ADMIN
- NET_ADMIN
devices:
- /dev/net/tun
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
volumes:
- ./zerotier-one:/var/lib/zerotier-one
#- ./init.sh:/init.sh
build:
dockerfile: ./Dockerfile
#entrypoint: sh -c "sh /init.sh"
#command: sh -c "sh /init.sh"
#tty: true
and Dockerfile
FROM zerotier/zerotier:latest
RUN apt-get update ;
RUN apt-get install iptables sudo -y ;
COPY init.sh /init.sh
RUN chmod 755 /init.sh
RUN sh -c 'sh /init.sh'
#CMD ["sh", "/init.sh"]
and init.sh
#!/bin/sh
#apt-get update ;
#apt-get install iptables sudo -y ;
PHY_IFACE=eth0; ZT_IFACE=ztxxxxxxxx
sudo iptables -t nat -A POSTROUTING -o $PHY_IFACE -j MASQUERADE
sudo iptables -A FORWARD -i $PHY_IFACE -o $ZT_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i $ZT_IFACE -o $PHY_IFACE -j ACCEPT
but when i use
docker compose up --build -d
i have this error
=> [zerotier-one internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 767B 0.0s
=> [zerotier-one internal] load metadata for docker.io/zerotier/zerotier:latest 0.0s
=> [zerotier-one internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [zerotier-one 1/6] FROM docker.io/zerotier/zerotier:latest 0.0s
=> [zerotier-one internal] load build context 0.0s
=> => transferring context: 29B 0.0s
=> CACHED [zerotier-one 2/6] RUN apt-get update ; 0.0s
=> CACHED [zerotier-one 3/6] RUN apt-get install iptables sudo -y ; 0.0s
=> CACHED [zerotier-one 4/6] COPY init.sh /init.sh 0.0s
=> CACHED [zerotier-one 5/6] RUN chmod 755 /init.sh 0.0s
=> ERROR [zerotier-one 6/6] RUN sh -c 'sh /init.sh' 0.4s
------
> [zerotier-one 6/6] RUN sh -c 'sh /init.sh':
0.373 iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)
0.375
0.394 iptables v1.8.7 (nf_tables): Couldn't load match `state':No such file or directory
0.395
0.396 Try `iptables -h' or 'iptables --help' for more information.
0.414 iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)
0.416
------
failed to solve: process "/bin/sh -c sh -c 'sh /init.sh'" did not complete successfully: exit code: 4
strange is if i open a container
docker exec -it zerotier-one /bin/bash
and type
sh /init.sh
works fine…
so how i can run this file or command after container is up?
thank you in advance