AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[container](unix)

Martin Hope
Newbyte
Asked: 2024-06-09 20:34:19 +0800 CST

如何在 Distrobox 容器中访问主机系统的系统 (dbus) 总线?

  • 5

我正在使用 Distrobox 开发应用程序,目前正在开发一个与系统总线上运行的服务交互的应用程序。

为了测试与系统总线和我想要交互的服务的连接,我使用以下命令:

$ gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1

如果我在主机系统上运行它,它会正常工作,并会给我一个接口列表以及它们相应的方法、信号和属性。但是,如果我在 Distrobox 容器内运行它,它只会给我以下信息:

$ gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1
Error connecting: Could not connect: No such file or directory

我推测这是因为 Distrobox 容器无法访问主机系统的系统总线,而且我没有在容器本身中运行任何初始化系统。我想允许在此 Distrobox 容器内运行的应用程序能够访问我的主机系统的系统总线。如何在 Distrobox 容器内实现这一点?

container
  • 1 个回答
  • 87 Views
Martin Hope
Colourful
Asked: 2024-04-03 02:28:01 +0800 CST

getdents() 系统调用似乎在容器内返回不同的结果

  • 10

我正在尝试读取文件的类型/dev/null。如果我使用stat()它,它会正确报告它是一个字符设备。

如果我使用getdents(),它还会报告它是一个字符设备 - 除非我在容器中运行它,在这种情况下它会说它是一个常规文件!

为什么在容器中运行它会产生不同的结果?

使用该镜像在最新版本的 docker 和 podman 上进行了测试,给出了相同的结果ubuntu:22.04。

下面是复制代码 - 该stat()方法始终有效,但getdents在容器内运行时会导致断言失败。另外值得注意的是,代码并不总是被复制 - 在某些系统/容器上它似乎仍然可以正常工作。

(在linux 6.8.2-arch2-1和podman 5.0.0上测试)

#include <assert.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/syscall.h>

#define BUF_SIZE 1024

struct linux_dirent {
    long           d_ino;
    off_t          d_off;
    unsigned short d_reclen;
    char           d_name[];
};

int main() {
    // stat approach

    struct stat st;
    stat("/dev/null", &st);

    printf("stat type: %d\n", st.st_mode & S_IFMT);

    assert((st.st_mode & S_IFMT) == S_IFCHR);

    // getdirents approach

    int fd, nread;
    char buf[BUF_SIZE];
    struct linux_dirent *d;
    int bpos;
    char d_type;

    fd = open("/dev", O_RDONLY | O_DIRECTORY);

    for (;;) {
        nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);

        for (bpos = 0; bpos < nread;) {
            d = (struct linux_dirent *)(buf + bpos);
            if (strcmp(d->d_name, "null") == 0) {
                d_type = *(buf + bpos + d->d_reclen - 1);
                printf("getdents type: %d\n", d_type);
                assert(d_type == DT_CHR);
                exit(EXIT_SUCCESS);
            }
            bpos += d->d_reclen;
        }
    }
    close(fd);

    exit(EXIT_SUCCESS);
}
container
  • 1 个回答
  • 230 Views
Martin Hope
Douglas
Asked: 2023-01-17 12:37:38 +0800 CST

使用 Unison 将我的桌面计算机与云中的容器同步

  • 6

我想使用 Unison 在我的台式电脑和云端容器之间同步一个目录。我有这种与 Unison 的合作,但我看到的问题是每次启动容器时,它都可以有不同的主机名和 IP 号,并且 sshd 将在不同的端口号上运行。

为了让这对我来说基本上是透明的,每次我启动容器时,我都会像这样编辑我的 ~/.ssh/config 文件:

Host pod
   User root
   Hostname 184.26.5.182
   Port 10666

我相应地替换了 IP 号和端口号。

完成此操作后,我可以使用ssh pod等登录容器。我可以毫无问题地运行 rsync 脚本,即使它们的主机别名“pod”已硬连接到它们中。(如果我知道如何使 rsync 与删除进行双向同步,那么我会使用它,但我很确定那是不可能的。)

我的 Unison 配置文件如下所示:

root = /Users/me/path/to/dir
root = ssh://pod//path/to/dir
 
ignore = Path subdir1
ignore = Path subdir2

不幸的是,这并不是很好,因为每次我启动容器时,我都会得到一个不同的端口号(IP 号通常不会改变),而 Unison 认为这是一个新的同步。这根本不是我想要的。

有没有办法告诉 Unison 忽略远程容器似乎已更改为另一台计算机的事实,并且只相信我的“pod”主机别名可以依赖主机身份?

container
  • 1 个回答
  • 19 Views
Martin Hope
Ôrel
Asked: 2022-09-20 05:40:49 +0800 CST

CLOSE_WAIT 在 kubernetes 节点上不可见

  • 1

调试一个tcp: out of memory 错误,我发现一个进程(来自一个容器)在CLOSE_WAIT状态上有很多连接,也就是08当我 cat 时/proc/XXX/net/tcp

但是 netstat 或 ss 都没有显示那些泄露的连接。

133: 0E03540A:9D9C 804CC2AD:01BB 08 00000000:00059D7A 00:00000000 00000000 0 0 316215 1 ffff8f677201df00 20 4 0 10 -1
134: 0E03540A:8316 80A7E940:01BB 08 00000000:00000000 00:00000000 00000000 0 0 255647 1 ffff8f67c9592600 20 4 1 10 -1
135:0E03540A:8874 808C7D4A:01BB 08 00000000:00037EED 00:0000000000000000000000000000000000000.000000 0 0 331603 1 FFFFFF68E37A7200 20 4 1 10-1
136: 1 136:0EDEBIDY000BC. 0EE0EBCC. 0EE0BCC.E222222222222222222222222222222222222222。 1 FFFF8F67BD1EDF00 20 4 0 10 -1
137:0E03540A:DAEC 804CC2AD:01BB 08 00000000:0005B41A 00:00000000000000000000000000000000000000000. 0 0 0 0 0 216048 1 FFFFFF567DAF9AF80 20
4.0138:0.0138:0.11 138:0.11 138: 00000000 0 0 243082 1 ffff8f67db637200 20 4 30 10 -1
140: 0E03540A:BAE4 800FB16C:01BB 08 00000000:000D8432 00:00000000 00000000 0 0 245062 1 ffff8f67640f8980 20 4 1 10 -1
141: 0E03540A:9754 804CC2AD:01BB 08 00000000:00003186 00:00000000 00000000 0 0 298890 1 ffff8f676e1a5f00 20 4 1 10 -1
142: 0E03540A:C6FC 800FB16C:01BB 08 00000000:000658C9 00:00000000 00000000 0 0 299343 1 ffff8f68dcef5580 20 4 0 10 -1
143: 0E03540A:CB24 804CC2AD:01BB 08 00000000:0005BBB4 00:00000000 00000000 0 0 316285 1 ffff8f6772019300 20 4 1 10 -1
144: 0E03540A:8204 80A7E940:01BB 08 00000000:0005DD3A 00:00000000 00000000 0 0 217390 1 ffff8f67dbc20000 20 4 0 10 -1
145: 0E03540A:8BC8 80016642:01BB 08 00000000:00059847 00:00000000 00000000 0 0 275095 1 ffff8f67b6d7a600 20 4 1 10 -1
146: 0E03540A:C612 8005FB8E:01BB 08 00000000:0003EC48 00:00000000 00000000 0 0 252281 1 ffff8f67cf014280 20 4 1 10 -1

为什么 netstat 没有显示这些连接以及如何在不深入研究每个进程细节的情况下获取它们?

tcp container
  • 1 个回答
  • 37 Views
Martin Hope
Peque
Asked: 2022-06-25 08:12:17 +0800 CST

在容器内运行“重新编码”时出错

  • 0

我正在运行一个 Fedora 容器:

podman run -it registry.fedoraproject.org/fedora:36

在这个容器内,我首先安装recode:

[root@388e917ba8ce /]# sudo dnf install recode

然后,在尝试执行时recode,我收到此错误:

[root@388e917ba8ce /]# touch deleteme.txt
[root@388e917ba8ce /]# recode windows1251..utf8 deleteme.txt
recode: /deleteme.txt failed: System detected problem in step `CP1251..UTF-8'

什么可能导致此错误?

请注意,当我recode在我的 Fedora 36 系统(没有容器)中运行时,我没有收到任何错误。此外,如果我使用 Ubuntu 映像,我也不会收到错误消息。

fedora container
  • 1 个回答
  • 30 Views
Martin Hope
Chuck
Asked: 2022-05-25 13:17:40 +0800 CST

podman play kube --network 没有正确连接网络

  • 0

我在 RHEL8.6 上使用 podman 来部署一个由两个容器组成的 pod,zabbix-server 和 postgres-server。为了部署容器,podman play kube在 .yaml 文件上使用以导入和运行 pod 配置。这是一个无根设置。

容器需要使用 DNS 通过内部网络进行通信。我podman create network mon用来创建一个名为“mon”的桥接网络,它启用了 DNS。

使用podman play kube monitoring.yaml --network mon,容器无法通过 DNS 相互通信。我通过手动创建 pod 和容器来测试设置,而不使用 podman play kube。在手动设置中,pod 中的容器能够使用 DNS 找到彼此。

手动设置:

podman pod create --name monitoring
podman network create mon
podman run -d --rm --network=mon --pod=monitoring --name postgres-server docker.io/timescale/timescaledb:latest-pg14
podman run -d --rm --network=mon --pod=monitoring --name zabbix-server docker.io/zabbix/zabbix-server-pgsql

周一网络配置:

[
    {
        "cniVersion": "0.4.0",
        "name": "mon",
        "plugins": [
            {
                "bridge": "cni-podman1",
                "hairpinMode": true,
                "ipMasq": true,
                "ipam": {
                    "ranges": [
                        [
                            {
                                "gateway": "10.89.0.1",
                                "subnet": "10.89.0.0/24"
                            }
                        ]
                    ],
                    "routes": [
                        {
                            "dst": "0.0.0.0/0"
                        }
                    ],
                    "type": "host-local"
                },
                "isGateway": true,
                "type": "bridge"
            },
            {
                "capabilities": {
                    "portMappings": true
                },
                "type": "portmap"
            },
            {
                "backend": "",
                "type": "firewall"
            },
            {
                "type": "tuning"
            },
            {
                "capabilities": {
                    "aliases": true
                },
                "domainName": "dns.podman",
                "type": "dnsname"
            }
        ]
    }
]

监控.yaml文件:

# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-3.4.7
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2022-05-24T13:40:30Z"
  labels:
    app: monitoring
  name: monitoring
spec:
  containers:
  - args:
    - postgres
    image: docker.io/timescale/timescaledb:latest-pg14
    name: postgres-server
    resources: {}
    securityContext:
      capabilities:
        drop:
        - CAP_MKNOD
        - CAP_NET_RAW
        - CAP_AUDIT_WRITE
  - args:
    - /usr/sbin/zabbix_server
    - --foreground
    - -c
    - /etc/zabbix/zabbix_server.conf
    image: docker.io/zabbix/zabbix-server-pgsql:latest
    name: zabbix-server
    resources: {}
    securityContext:
      capabilities:
        drop:
        - CAP_MKNOD
        - CAP_NET_RAW
        - CAP_AUDIT_WRITE
    volumeMounts:
    - mountPath: /var/lib/zabbix/export
      name: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8-pvc
    - mountPath: /var/lib/zabbix/snmptraps
      name: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec-pvc
  restartPolicy: Never
  volumes:
  - name: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8-pvc
    persistentVolumeClaim:
      claimName: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8
  - name: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec-pvc
    persistentVolumeClaim:
      claimName: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec
status: {}

故障排除

podman 文档表明podman network create支持附加创建的网络:https ://docs.podman.io/en/latest/markdown/podman-play-kube.1.html#network-mode-net

在手动podman exec -it <container> /bin/bash创建的容器上打开 shell ( ) ,我可以 ping zabbix-server 和 postgres-server:

$ podman exec -it zabbix-server /bin/bash
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.89.0.3       c61fdf070064 zabbix-server
10.89.0.1 host.containers.internal
bash-5.1$ ping postgres-server
PING postgres-server.dns.podman (10.89.0.2) 56(84) bytes of data.
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=1 ttl=64 time=0.051 ms
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=2 ttl=64 time=0.062 ms
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=3 ttl=64 time=0.100 ms
^C
--- postgres-server.dns.podman ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2045ms
rtt min/avg/max/mdev = 0.051/0.071/0.100/0.021 ms

在play kube容器上,ping 要么monitoring-<name>-server失败<name>-server。ping 手册和 play kube 设置上的 DNS 解析器成功返回。

bash-5.1$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.89.0.2       monitoring be3df46ca68d-infra
10.89.0.1 host.containers.internal

bash-5.1$ ping postgres-server
ping: postgres-server: Name does not resolve
bash-5.1$ ping monitoring-postgres-server
ping: monitoring-postgres-server: Name does not resolve
bash-5.1$ cat /etc/resolv.conf
search dns.podman
nameserver 10.89.0.1

使用podman inspect <container>,手动和 kube 播放设置都连接了 'mon' 网络。但是,在play kube设置中,网络设置的输出如下:

"NetworkMode": "container:49e7b0bafd4619b9bcb50b1b841aeee3cb910bf3c555a9788dc297e71c948092"

这与手动网络设置不同:

"NetworkMode": "bridge"

看起来好像“play kube”忽略了 --network 标志,而是创建了一个内部容器网络。使用kube play查看容器网络设置,两个容器上的 ips 是相同的。在手动设置中,IP 不同:

"Networks": {              
                "mon": {            
                    "EndpointID": "",
                    "Gateway": "10.89.0.1",
                    "IPAddress": "10.89.0.3",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "3e:30:b7:e2:1d:00",
                    "NetworkID": "mon",

Networks": {              
                "mon": {            
                    "EndpointID": "",
                    "Gateway": "10.89.0.1",
                    "IPAddress": "10.89.0.2",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "fa:1a:6b:f3:02:3a",
                    "NetworkID": "mon",

我已经在 Enforcing 模式下尝试了使用和不使用 SELinux 的 podman kube play。我也尝试以 root 身份运行此设置,但无济于事。

我已经使用以下版本测试了此设置:

  • 播客:3.4.7、4.0.2
  • RHEL:8.5、8.6

任何帮助将非常感激!

rhel container
  • 1 个回答
  • 232 Views
Martin Hope
Evan Carroll
Asked: 2021-10-07 09:04:46 +0800 CST

如何检查图像中的层数?

  • 2

假设我想检查图像中的层数,图像在达到最终形式之前被修改了多少次,我该怎么做?

container containers
  • 1 个回答
  • 266 Views
Martin Hope
Evan Carroll
Asked: 2021-10-05 19:21:05 +0800 CST

图像可以回滚吗?

  • 0

如果我正在处理具有多个图层的图像,是否可以回滚到前一层或重置到图像堆栈中的另一层?

图像上的 podman 等价物是git reset --hard HEAD^什么?

container podman
  • 1 个回答
  • 91 Views
Martin Hope
Evan Carroll
Asked: 2021-10-05 17:32:50 +0800 CST

我可以从存储库中提取图像并将其在本地保存为不同的名称吗?

  • 1

我可以用下拉图像podman pull

podman pull alpine:3

这目前将图像拉下为,

REPOSITORY                TAG             IMAGE ID      CREATED         SIZE
docker.io/library/alpine  3               14119a10abf4  5 weeks ago     5.87 MB

有没有将该图像保存为将来参考localhost/foo?

images container
  • 2 个回答
  • 92 Views
Martin Hope
E235
Asked: 2019-01-30 05:51:21 +0800 CST

如何替换 Linux 容器内 /bin 中的二进制文件

  • 1

我想做一些奇怪的容器,我的任务之一是替换uname二进制文件。
我编码它:

#include <stdio.h>
int main() {
   printf("This is a fake uname\n");
   return 0;
}  

编译它:

gcc uname.c -o uname

当我在我的 ubuntu 上运行它时它工作正常。

我创建了一个Dockerfile并将其复制到图像中:

cat > Dockerfile <<EOF
FROM alpine:latest
RUN rm /bin/uname
COPY uname /bin/
ENTRYPOINT sh;
WORKDIR /home
EOF  

并建造它docker build -t myimage -f Dockerfile .

当我运行图像时:

docker run -it --rm myimage  

该文件存在,但是当我尝试运行它时,它写道它不存在:

/home # uname
sh: uname: not found
/home # ls -lia uname
ls: uname: No such file or directory
/home # ls -lia /bin/uname
     35 -rwxr-xr-x    1 root     root          8600 Jan 29 13:27 /bin/uname
docker container
  • 1 个回答
  • 1502 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve