mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge remote-tracking branch 'origin/96-dns_issue-fix'
This commit is contained in:
commit
cdf90bb04b
3 changed files with 32 additions and 7 deletions
|
@ -34,12 +34,13 @@ type Container struct {
|
||||||
NetworkSettings *NetworkSettings
|
NetworkSettings *NetworkSettings
|
||||||
|
|
||||||
SysInitPath string
|
SysInitPath string
|
||||||
|
ResolvConfPath string
|
||||||
|
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
stdout *writeBroadcaster
|
stdout *writeBroadcaster
|
||||||
stderr *writeBroadcaster
|
stderr *writeBroadcaster
|
||||||
stdin io.ReadCloser
|
stdin io.ReadCloser
|
||||||
stdinPipe io.WriteCloser
|
stdinPipe io.WriteCloser
|
||||||
|
|
||||||
ptyMaster io.Closer
|
ptyMaster io.Closer
|
||||||
|
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
|
@ -61,6 +62,7 @@ type Config struct {
|
||||||
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
||||||
Env []string
|
Env []string
|
||||||
Cmd []string
|
Cmd []string
|
||||||
|
Dns []string
|
||||||
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +87,9 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
var flEnv ListOpts
|
var flEnv ListOpts
|
||||||
cmd.Var(&flEnv, "e", "Set environment variables")
|
cmd.Var(&flEnv, "e", "Set environment variables")
|
||||||
|
|
||||||
|
var flDns ListOpts
|
||||||
|
cmd.Var(&flDns, "dns", "Set custom dns servers")
|
||||||
|
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -122,6 +127,7 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
AttachStderr: flAttach.Get("stderr"),
|
AttachStderr: flAttach.Get("stderr"),
|
||||||
Env: flEnv,
|
Env: flEnv,
|
||||||
Cmd: runCmd,
|
Cmd: runCmd,
|
||||||
|
Dns: flDns,
|
||||||
Image: image,
|
Image: image,
|
||||||
}
|
}
|
||||||
// When allocating stdin in attached mode, close stdin at client disconnect
|
// When allocating stdin in attached mode, close stdin at client disconnect
|
||||||
|
|
|
@ -78,7 +78,7 @@ lxc.mount.entry = devpts {{$ROOTFS}}/dev/pts devpts newinstance,ptmxmode=0666,no
|
||||||
lxc.mount.entry = {{.SysInitPath}} {{$ROOTFS}}/sbin/init none bind,ro 0 0
|
lxc.mount.entry = {{.SysInitPath}} {{$ROOTFS}}/sbin/init none bind,ro 0 0
|
||||||
|
|
||||||
# In order to get a working DNS environment, mount bind (ro) the host's /etc/resolv.conf into the container
|
# In order to get a working DNS environment, mount bind (ro) the host's /etc/resolv.conf into the container
|
||||||
lxc.mount.entry = /etc/resolv.conf {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
|
lxc.mount.entry = {{.ResolvConfPath}} {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
|
||||||
|
|
||||||
|
|
||||||
# drop linux capabilities (apply mainly to the user root in the container)
|
# drop linux capabilities (apply mainly to the user root in the container)
|
||||||
|
|
19
runtime.go
19
runtime.go
|
@ -82,6 +82,7 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
||||||
if config.Hostname == "" {
|
if config.Hostname == "" {
|
||||||
config.Hostname = id[:12]
|
config.Hostname = id[:12]
|
||||||
}
|
}
|
||||||
|
|
||||||
container := &Container{
|
container := &Container{
|
||||||
// FIXME: we should generate the ID here instead of receiving it as an argument
|
// FIXME: we should generate the ID here instead of receiving it as an argument
|
||||||
Id: id,
|
Id: id,
|
||||||
|
@ -100,6 +101,24 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
||||||
if err := os.Mkdir(container.root, 0700); err != nil {
|
if err := os.Mkdir(container.root, 0700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If custom dns exists, then create a resolv.conf for the container
|
||||||
|
if len(config.Dns) > 0 {
|
||||||
|
container.ResolvConfPath = path.Join(container.root, "resolv.conf")
|
||||||
|
f, err := os.Create(container.ResolvConfPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
for _, dns := range config.Dns {
|
||||||
|
if _, err := f.Write([]byte("nameserver " + dns + "\n")); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
container.ResolvConfPath = "/etc/resolv.conf"
|
||||||
|
}
|
||||||
|
|
||||||
// Step 2: save the container json
|
// Step 2: save the container json
|
||||||
if err := container.ToDisk(); err != nil {
|
if err := container.ToDisk(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue