Unfortunately: no.
A similar feature request (#20179) has been open at the GitHub repository for almost 6 years, so I truly believe that this feature is not being implemented any time soon.
My current workaround is, similar to what @Zoredache mentioned, to add a bash script to your containers and set the desired gateway IP address through environment variables. The script deletes the default route and adds it back with the custom IP as the gateway.
Edit: the essence of my script:
if [ -n "$GW" ]; then
ip route delete default ;
ip route add default via $GW ;
fi
If you do want to change the default gateway of your container you run the container with the appropriate environment variable GW=192.168.0.1
and the script takes care of the rest. Furthermore, make sure to include the script in either the CMD
or ENTRYPOINT
of your Dockerfile
NOTE: Requires the iproute2
package.
Might not be the prettiest solution, but it gets the job done.