简体   繁体   English

Docker 为 linux Debian 和 Arch 编写文件

[英]Docker compose file for linux Debian and Arch

Hope I'm doing this correctly...希望我做对了......

First of we are using docker-compose with a yml file.首先我们使用 docker-compose 和一个 yml 文件。
Looking something like that:看起来像这样:

sudo docker-compose -f docker-compose.yml up -d

In the yml file we have something similar to:在 yml 文件中,我们有类似的内容:

version: '3.4'
services:
  MyContainer:
    image: "MyContainer:latest"
    container_name: MyContainer
    restart: always
    environment:
        - DISPLAY=unix$DISPLAY
        - QT_X11_NO_MITSHM=1
    devices:
        - /dev/dri:/dev/dri
    volumes:
        - /tmp/.X11-unix:/tmp/.X11-unix:rw
        - /dev/dri:/dev/dri
        - /usr/lib/x86_64-linux-gnu/libXv.so.1:/usr/lib/x86_64-linux-gnu/libXv.so.1:rw
        - ~/MyFiles/:/root/Myfiles
        - ~:/root/home

Now the problem starts.现在问题开始了。 We have two operating systems used by the team.我们有两个操作系统供团队使用。 One time Ubuntu and then Arch and Manjaro.一次是 Ubuntu,然后是 Arch 和 Manjaro。 As a experienced Linux User might know this will not work on Arch.作为有经验的 Linux 用户可能知道这在 Arch 上不起作用。 Because x86_64-linux-gnu is a folder in Ubuntu. This is a very specific folder on Debian/Ubuntu systems.因为x86_64-linux-gnu是Ubuntu里面的一个文件夹。这个在Debian/Ubuntu系统上是一个非常特殊的文件夹。 The equivalent on Arch/Manjaro and nearly every other Linux Distro is /usr/lib or /usr/lib64. Arch/Manjaro 和几乎所有其他 Linux Distro 上的等价物是 /usr/lib 或 /usr/lib64。

Of course a hack would be to make this folder to link into lib, but I don't want to do that for every new team-member/machine without Ubuntu.当然,一个 hack 是让这个文件夹链接到 lib,但我不想为没有 Ubuntu 的每个新团队成员/机器都这样做。

So these are all the upfront information to give.所以这些都是要提供的前期信息。 My Question is:我的问题是:

What is the best approach in your opinion to solve this problem?您认为解决此问题的最佳方法是什么?

I had a google search, but either I used the wrong keywords, or people don't have that problem, because they design their containers smarter.我进行了谷歌搜索,但要么我使用了错误的关键字,要么人们没有这个问题,因为他们设计的容器更智能。

I know that there are docker volumes that can be created and then used in the docker-compose file but for that, we would need to rerun the setup on all PC's, Laptops and Servers we have, would like to avoid that if possible...我知道可以创建 docker 卷,然后在 docker-compose 文件中使用,但为此,我们需要在我们拥有的所有 PC、笔记本电脑和服务器上重新运行设置,希望尽可能避免这种情况……

I have a lot to learn so if you have more experience and knowledge please be so kind and explain me my mistakes.我有很多东西要学,所以如果你有更多的经验和知识,请善待并解释我的错误。

Regards, Stefan问候,斯特凡

If you're trying to use the host display, host libraries, host filesystem, and host hardware devices, then the only thing you're getting out of Docker is an inconvenient packaging mechanism that requires root privileges to run.如果您尝试使用主机显示、主机库、主机文件系统和主机硬件设备,那么您从 Docker 中得到的唯一东西是一种不方便的打包机制,它需要 root 权限才能运行。 It'd be significantly easier to build a binary and run the application directly on the host.构建二进制文件并直接在主机上运行应用程序会容易得多。

If you must run this in Docker, the image should be self-contained: all of the code and libraries necessary to run the application needs to be in the image and copied in the Dockerfile .如果您必须在 Docker 中运行它,图像应该是独立的:运行应用程序所需的所有代码和库都需要在图像中并复制到Dockerfile中。 Most images start FROM some Linux distribution (maybe indirectly through a language runtime) and so you need to install the required libraries using its package manager.大多数图像FROM某些 Linux 发行版开始(可能间接通过语言运行时),因此您需要使用其 package 管理器安装所需的库。

FROM ubuntu:18.04
RUN apt-get update \
 && apt-get install --no-install-recommends --assume-yes \
      libxv1
...

Bind-mounting binaries or libraries into containers leads to not just filesystem inconsistencies like you describe but in some cases also binary-compatibility issues.将二进制文件或库绑定到容器中不仅会导致您描述的文件系统不一致,而且在某些情况下还会导致二进制兼容性问题。 The bind mount won't work properly on a MacOS host, for instance.例如,绑定安装将无法在 MacOS 主机上正常工作。 (Earlier recipes for using the Docker socket inside a Docker container recommended bind-mounting /usr/bin/docker into the container, but this could hit problems if a CentOS host Docker was built against different shared libraries than an Ubuntu container Docker.) (早期在 Docker 容器中使用 Docker 套接字的方法建议将/usr/bin/docker docker 绑定到容器中,但是如果 CentOS 主机 Docker 是针对与 8820787740318183968804 容器不同的共享库构建的,这可能会遇到问题)

volumes section in docker compose supports environment variables. docker 中的卷部分 compose 支持环境变量。 You can make use of that and it will be machine specific.您可以利用它,它将是特定于机器的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM