Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/ContainerCommands/Container/ContainerExec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ extension Application {
gid: processFlags.gid, defaultUser: defaultUser)
config.user = user
config.supplementalGroups.append(contentsOf: additionalGroups)
if !self.processFlags.ulimits.isEmpty {
config.rlimits = try Parser.rlimits(self.processFlags.ulimits)
}

do {
let io = try ProcessIO.create(tty: tty, interactive: stdin, detach: self.detach)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ContainerCommands/Machine/MachineRun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ extension Application {
workingDirectory: cwd,
terminal: tty,
user: user,
supplementalGroups: additionalGroups
supplementalGroups: additionalGroups,
rlimits: try Parser.rlimits(processFlags.ulimits)
)

let io = try ProcessIO.create(tty: tty, interactive: interactive, detach: detach)
Expand Down
17 changes: 17 additions & 0 deletions Tests/IntegrationTests/Containers/TestCLIExecCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,21 @@ struct TestCLIExecCommand {
_ = try f.getContainerStatus(name)
}
}

@Test func testExecUlimitNofile() async throws {
try await ContainerFixture.with { f in
let image = WarmupImage.alpine320.rawValue
let name = "\(f.testID)-c"
try f.doCreate(name: name, image: image)
f.addCleanup { try? f.doStop(name) }
try f.doStart(name)
try await f.waitForContainerRunning(name)

let nofile = try f.run(["exec", "--ulimit", "nofile=1024:2048", name, "sh", "-c", "ulimit -n"])
.check().output
.trimmingCharacters(in: .whitespacesAndNewlines)
#expect(nofile == "1024", "expected exec --ulimit to set the nofile soft limit, got \(nofile)")
try f.doStop(name)
}
}
}
4 changes: 3 additions & 1 deletion docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Executes a command inside a running container. It uses the same process flags as
**Usage**

```bash
container exec [--detach] [--env <env> ...] [--env-file <env-file> ...] [--gid <gid>] [--interactive] [--tty] [--user <user>] [--uid <uid>] [--workdir <dir>] [--debug] <container-id> <arguments> ...
container exec [--detach] [--env <env> ...] [--env-file <env-file> ...] [--gid <gid>] [--interactive] [--tty] [--user <user>] [--uid <uid>] [--ulimit <limit>] [--workdir <dir>] [--debug] <container-id> <arguments> ...
```

**Arguments**
Expand All @@ -382,6 +382,7 @@ container exec [--detach] [--env <env> ...] [--env-file <env-file> ...] [--gid <
* `-t, --tty`: Open a TTY with the process
* `-u, --user <user>`: Set the user for the process (format: name|uid[:gid])
* `--uid <uid>`: Set the user ID for the process
* `--ulimit <limit>`: Set resource limits (format: `<type>=<soft>[:<hard>]`)
* `-w, --workdir, --cwd <dir>`: Set the initial working directory inside the container

### `container export`
Expand Down Expand Up @@ -1168,6 +1169,7 @@ container machine run [<options>] [<executable>] [<arguments> ...]
* `-t, --tty`: Open a TTY with the process
* `-u, --user <user>`: Set the user for the process (format: name|uid[:gid])
* `--uid <uid>`: Set the user ID for the process
* `--ulimit <limit>`: Set resource limits (format: `<type>=<soft>[:<hard>]`)
* `-w, --workdir, --cwd <dir>`: Set the initial working directory inside the container

**Examples**
Expand Down