簡體   English   中英

沒有權限更改docker容器中的tty模式

[英]No permissions to change tty mode inside a docker container

我正在嘗試在docker容器中運行一些軟件,它希望為當前使用的tty執行VT_SETMODE。 這將始終失敗並顯示“不允許操作”的錯誤。

我試過玩權限/組沒有運氣。

最后,我創建了一個小片段來重現錯誤:

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>

int main() {
        const char *tty_path;
        tty_path = "/dev/tty1";

        int fd = open(tty_path, O_RDWR | O_CLOEXEC);

        if (fd < 0) {
                printf("ERROR: Failed to open %s\n", strerror(errno));
                return 1;
        }

        struct vt_mode mode = {
                .mode = VT_AUTO,
        };
        errno = 0;

        ioctl(fd, VT_SETMODE, &mode);

        if (errno) {
                printf("ERROR: %s\n", strerror(errno));
                return 1;
        }

        return 0;
}

我使用簡單的dockerfile在docker容器中運行代碼:

FROM archlinux/base

RUN pacman -Sy --noconfirm gcc

那是從命令開始的:

docker build -f Dockerfile -t tty-test . && docker run --device /dev/tty1 -v $HOME/tty-test:/volume -it tty-test /bin/bash -c 'cd /volume && gcc tty_r.c && ./a.out ; /bin/bash'

輸出是這樣的:

ERROR: Operation not permitted

任何人都可以解釋為什么無法從容器中訪問tty,或者是否有某種方法可以對容器進行更多控制?

好吧,似乎我已經解決了我自己的問題。 我試圖在沒有權限進行tty配置的容器中運行代碼。 --cap-add SYS_TTY_CONFIG--cap-add SYS_TTY_CONFIG run命令修復了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM