Firstly, running the iptables command during the docker build process will never make sense; even if it works, the iptables command only changes the configuration of your kernel runtime. These changes will not be saved in the Docker image and will not be available when the container starts.
Secondly, even if you start the iptables container after starting the container (and not when creating the container), it will still fail, because Docker containers by default do not have the necessary rights to change the iptables configuration (either change the network as a whole or mount file systems, etc.). You can run a container with the --privileged flag, but this is probably not what you want to do (since it gives a number of additional privileges on the container that are probably not needed, and from a security point of view, it is a good idea to only grant privileges which are absolutely necessary).
You usually use this with the Docker -p option to connect your host ports to ports in your container, for example:
docker run -p 80:8080 temp
This will connect port 80 on your host to port 8080 on the container.
If this is not what you need, the easiest way is to configure the application in your container to work on the desired port.
source share