How can I run a script in a docker container with additional capabilities, such as NET_ADMIN
?
I'm testing out some commands that I'd like to run in a docker image that require the NET_ADMIN
permissions. For example, this works:
docker run --rm -it --cap-add 'NET_ADMIN' debian:stable-slim "iptables -L"
But if I want to execute a script (via docker exec
), then suddenly the --cap-add
option is not available.
root@disp8686:~# cat << EOF > docker_script.sh
> apt-get update
> apt-get -y install iptables
> iptables -L
> EOF
root@disp8686:~# docker exec -it --cap-add 'NET_ADMIN' debian:stable-slim docker_script.sh
unknown flag: --cap-add
See 'docker exec --help'.
root@disp8686:~#
Why does --cap-add
exist for docker run
but not docker exec
and how can I run a script in a docker container using --cap-add
?