Skip to content

Commit f717cb8

Browse files
Merge pull request #87 from Roblox/hostname
Add support for hostname.
2 parents 6600111 + c86faf9 commit f717cb8

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
100100
| **cwd** | string | no | Specify the current working directory for your container process. If the directory does not exist, one will be created for you. |
101101
| **privileged** | bool | no | Run container in privileged mode. Your container will have all linux capabilities when running in privileged mode. |
102102
| **pids_limit** | int64 | no | An integer value that specifies the pid limit for the container. Defaults to unlimited. |
103+
| **hostname** | string | no | The hostname to assign to the container. When launching more than one of a task (using `count`) with this option set, every container the task starts will have the same hostname. |
103104
| **host_dns** | bool | no | Default (`true`). By default, a container launched using `containerd-driver` will use host `/etc/resolv.conf`. This is similar to [`docker behavior`](https://docs.docker.com/config/containers/container-networking/#dns-services). However, if you don't want to use host DNS, you can turn off this flag by setting `host_dns=false`. |
104105
| **seccomp** | bool | no | Enable default seccomp profile. List of [`allowed syscalls`](https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L395). |
105106
| **seccomp_profile** | string | no | Path to custom seccomp profile. `seccomp` must be set to `true` in order to use `seccomp_profile`. The default `docker` seccomp profile found [`here`](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) can be used as a reference, and modified to create a custom seccomp profile. |

containerd/containerd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
176176
// Set CPU Shares.
177177
opts = append(opts, oci.WithCPUShares(uint64(containerConfig.CPUShares)))
178178

179+
// Set Hostname
180+
hostname := containerConfig.ContainerName
181+
if config.Hostname != "" {
182+
hostname = config.Hostname
183+
}
184+
opts = append(opts, oci.WithHostname(hostname))
185+
179186
// Add linux devices into the container.
180187
for _, device := range config.Devices {
181188
opts = append(opts, oci.WithLinuxDevice(device, "rwm"))

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ var (
100100
"devices": hclspec.NewAttr("devices", "list(string)", false),
101101
"privileged": hclspec.NewAttr("privileged", "bool", false),
102102
"pids_limit": hclspec.NewAttr("pids_limit", "number", false),
103+
"hostname": hclspec.NewAttr("hostname", "string", false),
103104
"host_dns": hclspec.NewDefault(
104105
hclspec.NewAttr("host_dns", "bool", false),
105106
hclspec.NewLiteral("true"),
@@ -169,6 +170,7 @@ type TaskConfig struct {
169170
Sysctl hclutils.MapStrStr `codec:"sysctl"`
170171
Privileged bool `codec:"privileged"`
171172
PidsLimit int64 `codec:"pids_limit"`
173+
Hostname string `codec:"hostname"`
172174
HostDNS bool `codec:"host_dns"`
173175
ImagePullTimeout string `codec:"image_pull_timeout"`
174176
ExtraHosts []string `codec:"extra_hosts"`

example/redis.nomad

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ job "redis" {
66
driver = "containerd-driver"
77

88
config {
9-
image = "redis:alpine"
10-
seccomp = true
11-
cwd = "/home/redis"
9+
image = "redis:alpine"
10+
hostname = "foobar"
11+
seccomp = true
12+
cwd = "/home/redis"
1213
}
1314

1415
resources {

tests/001-test-redis.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ test_redis_nomad_job() {
3434
exit 1
3535
fi
3636

37+
echo "INFO: Exec redis job and check hostname is foobar."
38+
hostname=$(nomad alloc exec -job redis hostname)
39+
if [ $hostname != "foobar" ]; then
40+
echo "ERROR: hostname is not foobar."
41+
exit 1
42+
fi
43+
3744
echo "INFO: Check if default seccomp is enabled."
3845
output=$(nomad alloc exec -job redis cat /proc/1/status | grep Seccomp)
3946
seccomp_code=$(echo $output|cut -d' ' -f2)

0 commit comments

Comments
 (0)