docker command line list arguments

When I am starting the docker daemon I am modifying the dns server so that the containers have a modified /etc/resolv.conf. Looking at the usage message I see:

$ docker --help
Usage: docker [OPTIONS] COMMAND [arg...]

A self-sufficient runtime for linux containers.

Options:
  --api-enable-cors=false                    Enable CORS headers in the remote API
  -b, --bridge=""                            Attach containers to a prexisting network bridge
                                             use 'none' to disable container networking
  --bip=""                                   Use this CIDR notation address for the network bridge's IP, not compatible with -b
  -D, --debug=false                          Enable debug mode
  -d, --daemon=false                         Enable daemon mode
  --dns=[]                                   Force Docker to use specific DNS servers
  --dns-search=[]                            Force Docker to use specific DNS search domains
  -e, --exec-driver="native"                 Force the Docker runtime to use a specific exec driver

... etc ...

The –dns is what I want to pass, it shows a ‘list’ with the [], which after much trial and error I finally got this to work:

  • Docker push with artifactory
  • Docker Ubuntu 12.04
  • Pushing and pulling to/from private docker registry is horribly slow
  • is it possible to run virtualbox inside a docker container
  • Use environment variables in CMD
  • Accessing Elastic Beanstalk environment properties in Docker
  • --dns 127.0.0.1 --dns 8.8.8.8
    

    which deposits :

    nameserver 127.0.0.1
    nameserver 8.8.8.8
    

    in to the /etc/resolv.conf file.

    Is this the correct way to provide a list to docker (and presumably any go) program?

  • Docker Architecture for a test server
  • Docker Disable legacy registry using osx
  • Multiple docker containers as web server on a single IP
  • Docker + Virtual Box = VT-x is not available (VERR_VMX_NO_VMX)
  • Could not find jenkins_home folder in Ubuntu after downloading the Docker Jenkins Image
  • Rails Puma inside of Docker Instance stops responding from inactivity
  • One Solution collect form web for “docker command line list arguments”

    This is a way of passing multiple arguments to a program in Go but certainly not the only way. This is accomplished by defining a type that implements the Value interface. The flag package on flag.Parse() iterates though the argument list matching the name to a registered Value and calling the Set(string) function on the Value. You can use this to append each value of a given name to a slice.

    type numList []int
    
    func (l *numList) String() string {
       return "[]"
    }
    
    func (l *numList) Set(value string) error {
        number, err := strconv.Atoi(value)
    
        if err != nil {
            return fmt.Errorf("Unable to parse number from value \"%s\"", value)
        }
    
        *l = append(*l, number)
        return nil
    }
    

    This new type can be registered as a flag variable. In the following example the application takes n num command line arguments that are converted to an integer and added to a list.

    var numbers numList
    
    func main() {
        flag.Var(&numbers, "num", "A number to add to the summation"
        flag.Parse()
    
        sum := 0
        for _, num := range numbers {
           sum += num
        }
    
        fmt.Printf("The sum of your flag arguments is %d.\n", sum)
    }
    

    This could have been easily done with a string flag and have users pass a delimited list. There is no established convention within the Go language and each application can provide whatever implementation of best fit.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.