Home > OS >  Run docker container always with --network host
Run docker container always with --network host

Time:03-03

Beginner docker user here.

Is there a way that I create a docker image that when you run it it will ALWAYS run with the --network host options?

So that when I do docker run mydockerimage it will automatically do docker run --network host mydockerimage?

CodePudding user response:

This is a very strange request but one possibility is to override the docker function in your ~/.bashrc file by appending this snippet:

docker() {
  if [ "$1" == "run" ]; then
     for var in "$@"
     do
        if [ "$var" == "mydockerimage" ]; then
           trigger=true      
        fi    
     done
     if [ "$trigger" == "true" ]; then
        /usr/local/bin/docker "$1" --network host "${@:2}"
        return
     fi
  fi
  /usr/local/bin/docker "$@"
}
  • Related