Skip to content

Commit 418cd4a

Browse files
Merge pull request #33 from Roblox/host_network
Add support for host network.
2 parents 83af9c1 + dfb312c commit 418cd4a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
8686
| **args** | []string | no | Arguments to the command. |
8787
| **privileged** | bool | no | Run container in privileged mode. Your container will have all linux capabilities when running in privileged mode. |
8888
| **readonly_rootfs** | bool | no | Container root filesystem will be read-only. |
89+
| **host_network** | bool | no | Enable host network. This is equivalent to `--net=host` in docker. |
8990
| **cap_add** | []string | no | Add individual capabilities. |
9091
| **cap_drop** | []string | no | Drop invidual capabilities. |
9192
| **devices** | []string | no | A list of devices to be exposed to the container. |

containerd/containerd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ func (d *Driver) createContainer(image containerd.Image, containerName, containe
7070
opts = append(opts, oci.WithRootFSReadonly())
7171
}
7272

73+
// Enable host network.
74+
// WithHostHostsFile bind-mounts the host's /etc/hosts into the container as readonly.
75+
// WithHostResolvconf bind-mounts the host's /etc/resolv.conf into the container as readonly.
76+
if config.HostNetwork {
77+
opts = append(opts, oci.WithHostNamespace(specs.NetworkNamespace), oci.WithHostHostsFile, oci.WithHostResolvconf)
78+
}
79+
7380
// Add capabilities.
7481
if len(config.CapAdd) > 0 {
7582
opts = append(opts, oci.WithAddedCapabilities(config.CapAdd))

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var (
9494
"devices": hclspec.NewAttr("devices", "list(string)", false),
9595
"privileged": hclspec.NewAttr("privileged", "bool", false),
9696
"readonly_rootfs": hclspec.NewAttr("readonly_rootfs", "bool", false),
97+
"host_network": hclspec.NewAttr("host_network", "bool", false),
9798
"mounts": hclspec.NewBlockList("mounts", hclspec.NewObject(map[string]*hclspec.Spec{
9899
"type": hclspec.NewDefault(
99100
hclspec.NewAttr("type", "string", false),
@@ -142,6 +143,7 @@ type TaskConfig struct {
142143
Devices []string `codec:"devices"`
143144
Privileged bool `codec:"privileged"`
144145
ReadOnlyRootfs bool `codec:"readonly_rootfs"`
146+
HostNetwork bool `codec:"host_network"`
145147
Mounts []Mount `codec:"mounts"`
146148
}
147149

0 commit comments

Comments
 (0)