I run a Jenkins container instance on our server with this command:
docker run --name jenkins --restart=on-failure -d \
--network jenkins --env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/jenkincerts/client --env DOCKER_TLS_VERIFY=1 \
-p 8180:8080 -p 50000:50000 \
-v jenkins-home:/var/jenkins_home \
-v docker-certs-jk:/jenkincerts/client:ro \
myjenkin
But I find that port 8180 is exposed to the world, so I do research and find a solution to add a iptables rule with the command:
iptables -I DOCKER-USER -i eth0 ! -s 127.0.0.1 -j DROP
The result is that port is closed, but my Jenkins instance cannot access the internet to download...
Can anyone help me to close exposing ports to the world, but my Jenkins can still access the internet?