Linux Networking – Docker Container to Remote Host via Gateway without using route add?

I’m struggling with a networking issue.

I have a Docker instance running on with all the containers on the network. With Vagrant you would do something like sudo route add -net netmask gw to access the subnet.

  • RoR Processing messages off an Message Queue
  • Run project dependencies commands from dockerfile
  • Unable to connect to MySQL in Docker from local host (Docker for Mac beta)
  • Running docker-maven-plugin on the very end of parent pom building
  • Push access during gitlab ci process
  • Parameters to pass to docker run automatically on startup
  • However, when I run route add inside the container I get

    SIOCADDRT: Operation not permitted

    What can I do? Is there anything like Socat? I don’t want to add the NETCAP capability.

  • Docker on a Server 2016 Virtual Machine
  • polkit-gnome-authentication-agent-1 fail to start in docker without privileged flag
  • Jenkins inheritance plugin jobs are run in infinite loop
  • Docker - Restrictions regarding naming container
  • How to connect to a SQL instance in an App Engine custom runtime Dockerfile?
  • Is there any way to install Docker Tooling Kit in mars on Windows
  • One Solution collect form web for “Linux Networking – Docker Container to Remote Host via Gateway without using route add?”

    You need the right permissions for this. Apparently, there are at least two ways do do that:

    One from here:

    docker exec --privileged container ip route add default via dev eth0

    The other option is to expose the netns from here:

    pid=($sudo docker inspect -f '{{.State.Pid}}' container)
    sudo mkdir -p /var/run/netns
    sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
    sudo ip netns exec $pid ip route add default via
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.