mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
bind mount /etc/hosts and /etc/hostname
This commit is contained in:
parent
0a436e03b8
commit
4f2e59f94a
4 changed files with 33 additions and 8 deletions
27
builder.go
27
builder.go
|
@ -3,6 +3,7 @@ package docker
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
@ -119,7 +120,31 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
|||
if err := container.ToDisk(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Step 3: register the container
|
||||
|
||||
// Step 3: if hostname, build hostname and hosts files
|
||||
container.HostnamePath = path.Join(container.root, "hostname")
|
||||
ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
|
||||
|
||||
hostsContent := []byte("127.0.0.1\tlocalhost\n" +
|
||||
"::1\t\tlocalhost ip6-localhost ip6-loopback\n" +
|
||||
"fe00::0\t\tip6-localnet\n" +
|
||||
"ff00::0\t\tip6-mcastprefix\n" +
|
||||
"ff02::1\t\tip6-allnodes\n" +
|
||||
"ff02::2\t\tip6-allrouters\n")
|
||||
|
||||
container.HostsPath = path.Join(container.root, "hosts")
|
||||
|
||||
if container.Config.Domainname != "" {
|
||||
hostsContent = append([]byte("127.0.0.1\t"+container.Config.Hostname+"."+container.Config.Domainname+" "+container.Config.Hostname+"\n"+
|
||||
"::1\t\t"+container.Config.Hostname+"."+container.Config.Domainname+" "+container.Config.Hostname+"\n"), hostsContent...)
|
||||
} else {
|
||||
hostsContent = append([]byte("127.0.0.1\t"+container.Config.Hostname+"\n"+
|
||||
"::1\t\t"+container.Config.Hostname+"\n"), hostsContent...)
|
||||
}
|
||||
|
||||
ioutil.WriteFile(container.HostsPath, hostsContent, 0644)
|
||||
|
||||
// Step 4: register the container
|
||||
if err := builder.runtime.Register(container); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ type Container struct {
|
|||
|
||||
SysInitPath string
|
||||
ResolvConfPath string
|
||||
HostnamePath string
|
||||
HostsPath string
|
||||
|
||||
cmd *exec.Cmd
|
||||
stdout *utils.WriteBroadcaster
|
||||
|
@ -702,9 +704,6 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|||
params = append(params, "-e", "TERM=xterm")
|
||||
}
|
||||
|
||||
params = append(params, "-h", container.Config.Hostname)
|
||||
params = append(params, "-d", container.Config.Domainname)
|
||||
|
||||
// Setup environment
|
||||
params = append(params,
|
||||
"-e", "HOME=/",
|
||||
|
|
|
@ -30,6 +30,10 @@ lxc.network.ipv4 = {{.NetworkSettings.IPAddress}}/{{.NetworkSettings.IPPrefixLen
|
|||
{{$ROOTFS := .RootfsPath}}
|
||||
lxc.rootfs = {{$ROOTFS}}
|
||||
|
||||
# enable domain name support
|
||||
lxc.mount.entry = {{.HostnamePath}} {{$ROOTFS}}/etc/hostname none bind,ro 0 0
|
||||
lxc.mount.entry = {{.HostsPath}} {{$ROOTFS}}/etc/hosts none bind,ro 0 0
|
||||
|
||||
# use a dedicated pts for the container (and limit the number of pseudo terminal
|
||||
# available)
|
||||
lxc.pts = 1024
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -93,8 +92,7 @@ func SysInit() {
|
|||
var u = flag.String("u", "", "username or uid")
|
||||
var gw = flag.String("g", "", "gateway address")
|
||||
var workdir = flag.String("w", "", "workdir")
|
||||
var hostname = flag.String("h", "", "hostname")
|
||||
var domainname = flag.String("d", "", "domainname")
|
||||
|
||||
var flEnv ListOpts
|
||||
flag.Var(&flEnv, "e", "Set environment variables")
|
||||
|
||||
|
@ -103,7 +101,6 @@ func SysInit() {
|
|||
cleanupEnv(flEnv)
|
||||
setupNetworking(*gw)
|
||||
setupWorkingDirectory(*workdir)
|
||||
setupHostname(*hostname, *domainname)
|
||||
changeUser(*u)
|
||||
executeProgram(flag.Arg(0), flag.Args())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue