【问题标题】:Converting a program into a docker container将程序转换为 docker 容器
【发布时间】:2021-04-26 00:46:09
【问题描述】:

我正在尝试转换这个程序:

下载JetAdvice Edge

完整安装指南可见here

从安装到 linux 机器,再到 Docker 容器。

我需要多个运行的实例,我在业余时间一直在使用 Docker,现在终于可以在我的工作中使用了!

当我构建它时,我已经完成了 dockerfile(我认为),它会下载并安装它需要的东西,并且构建完成没有问题。

但是,我无法运行 JetAdvice 程序/服务! 我读过,如果我想在一个容器中运行多个东西,我应该使用主管,并且由于 JetEdge 程序有 3 个正在运行的服务,我正在使用它。

这是我的 dockerfile:

FROM ubuntu

MAINTAINER me

EXPOSE 33322
COPY startup.sh /opt/scripts/startup.sh
RUN apt-get update && \
    apt-get install -y apt-utils wget libunwind8 icu-devtools supervisor 
RUN mkdir -p -- /var/log/supervisor /opt/print/download /opt/print/edgeinstaller /opt/scripts

RUN wget https://app.jetadvice.com/install/edge/jetadvice-edge-linux-x64.tar -P /opt/print/download && \
    tar -xvf /opt/print/download/jetadvice-edge-linux-x64.tar -C /opt/print/edgeinstaller

RUN chmod +x /opt/print/edgeinstaller/Installer && \
    /opt/print/edgeinstaller/Installer install

RUN chmod +x /usr/bin/JetAdvice/Edge/Edge && \
    chmod +x /usr/bin/JetAdvice/Updater/Updater && \
    chmod +x /usr/bin/JetAdvice/EdgeUI/EdgeUi && \
    chmod +x /opt/scripts/startup.sh

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["/opt/scripts/startup.sh"]

这是我的 supervisord.conf

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:JetAdvice-Edge]
command=/usr/bin/JetAdvice/Edge/Edge

[program:JetAdvice-Updater]
command=/usr/bin/JetAdvice/Updater/Updater

[program:JetAdvice-Edge-UI]
command=/usr/bin/JetAdvice/EdgeUI/EdgeUi

还有 startup.sh 脚本:

#!/bin/sh
#somethingvariblehere
/usr/bin/supervisord

我尝试了很多方法来运行 JetAdvice,但我无法让程序运行。

有关信息,这是 JedAdvice-Edge.service 文件之一:

Description=JetAdvice Edge connector service
Wants=network.target
After=syslog.target network-online.target

[Service]
Type = simple
ExecStart=/usr/bin/JetAdvice/Edge/Edge
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

如果我登录到我的 docker 容器并尝试运行该服务,我会收到此错误

root@6727e8f42044:/# service JetAdvice-Updater start
JetAdvice-Updater: unrecognized service

如果我尝试直接运行程序,我会得到:

root@6727e8f42044:/# /usr/bin/JetAdvice/Edge/Edge
bash: /usr/bin/JetAdvice/Edge/Edge: Permission denied
root@6727e8f42044:/# ./usr/bin/JetAdvice/Edge/Edge
bash: ./usr/bin/JetAdvice/Edge/Edge: Permission denied

我尝试在 /usr/bin/JetAdvice/Edge/Edge 上执行 chmod +x,然后程序似乎运行了 3 秒,然后什么也没发生。

root@6727e8f42044:/# chmod +x /usr/bin/JetAdvice/Edge/Edge
root@6727e8f42044:/# /usr/bin/JetAdvice/Edge/Edge
root@6727e8f42044:/#

我什至没有接近 linux 专家,但我无法想象我正在尝试做的事情是无法完成的。 那么我做错了什么,下一步是什么?

JetEdge 团队的工作 install.json 文件

{
  "InstallConfig": {
    "ApiClient": {
      "SignIn": {
        "InstallKey": "prettykeyhere",
        "DcaInstanceID": "prettyidhere"
      },
      "HttpLogging": {
        "MaxSize": 10240,
        "LogHttp": false
      },
      "Proxy": {
        "Address": "",
        "Port": 8080,
        "AutoDetect": true
      }
    },
    "ApiEndpoint": {
      "LoginBaseAddress": "https://auth.eu.edge-api.com",
      "BaseAddress": "https://dr.eu.edge-api.com",
      "ConfigBaseAddress": "https://config.eu.edge-api.com",
      "StayAliveBaseAddress": "https://p.eu.edge-api.com",
      "UpdateBaseAddress": "https://upd.eu.edge-api.com",
      "UiApiBaseAddress": "https://ui.eu.edge-api.com",
      "RangesBaseAddress": "https://ranges.eu.edge-api.com",
      "LoggerBaseAddress": "https://log.eu.edge-api.com",
      "StatusBaseAddress": "https://status.eu.edge-api.com"
    },
    "Installs": [
      {
        "Product": 1,
        "Folder": "C:\\Program Files (x86)\\JetAdvice\\Updater",
        "ServiceName": "JetAdvice-Updater",
        "ServiceExe": "Updater.dll",
        "Version": "0.4.18.0",
        "BuildRID": "win-x86",
        "Oem": 0
      },
      {
        "Product": 10,
        "Folder": "C:\\Program Files (x86)\\JetAdvice\\Edge",
        "ServiceName": "JetAdvice-Edge",
        "ServiceExe": "Edge.dll",
        "Version": "0.4.24.0",
        "BuildRID": "win-x86",
        "Oem": 0
      },
      {
        "Product": 20,
        "Folder": "C:\\Program Files (x86)\\JetAdvice\\EdgeUI",
        "ServiceName": "JetAdvice-Edge-UI",
        "ServiceExe": "EdgeUi.dll",
        "Version": "0.4.1.0",
        "BuildRID": "win-x86",
        "Oem": 0
      }
    ]
  }
}

我为测试生成的密钥是: 4809b732-eb36-413f-8993-bd8d1f2e2942

编辑,我已更新 dockerfile,并将 startup.sh 脚本添加到 OP。

【问题讨论】:

    标签: docker dockerfile supervisord


    【解决方案1】:

    我稍微修改了你的 Dockerfile。

    FROM ubuntu:20.04
    
    EXPOSE 33322
    
    RUN apt-get update && \
        apt-get install -y apt-utils wget libunwind8 icu-devtools supervisor 
    
    #RUN apt-get install -y systemctl
    #RUN apt-get install -y systemd
    
    RUN mkdir -p -- /var/log/supervisor /opt/print/download /opt/print/edgeinstaller
    
    RUN wget https://app.jetadvice.com/install/edge/jetadvice-edge-linux-x64.tar -P /opt/print/download && \
        tar -xvf /opt/print/download/jetadvice-edge-linux-x64.tar -C /opt/print/edgeinstaller && \
        chmod +x /opt/print/edgeinstaller/Installer && \
        /opt/print/edgeinstaller/Installer install
        
    RUN chmod +x /usr/bin/JetAdvice/Edge/Edge
    COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
    
    CMD ["/usr/bin/supervisord"]
    

    我已经添加了这一行 RUN chmod +x /usr/bin/JetAdvice/Edge/Edge 用于将 +x 添加到可执行文件中。

    现在,当我启动容器时,它给了我一个错误,它停止了supervisord。 在/usr/share/JetAdvice/Edge/LogFiles 下,您可以找到 JetAdvice Edge 记录此错误的日志

    install.json - 缺少安装密钥。 (参数'InstallKey')

    在 EF.JA.Edge.Service.Windows.Program.c.b__2_3(HostBuilderContext hostContext、IServiceCollection 服务)在 Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() 在 Microsoft.Extensions.Hosting.HostBuilder.Build() 在 EF.JA.Edge.Service.Windows.Program.Main(String[] args)

    我在/usr/share/JetAdvice/Edge/Config/Shared下找到了install.json文件,里面有InstallKey这个json字段

    {
      "InstallConfig": {
        "ApiClient": {
          "SignIn": {
            "InstallKey": "",
            "DcaInstanceID": "e5860224-12a6-429e-b931-86c50a7a5900"
          },
    [..]
    }
    

    我在 google 上找到了这个web site about JetAdvice,上面写着:

    下载 JetAdvice Edge 并生成安装密钥

    我没有帐户,但我想您必须生成密钥并设置 install.json。

    【讨论】:

    • 哇!这是很多信息!没错,我为每个客户获取了一个帐户密钥,它应该在 json 文件中!我希望在安装后可以从 Web 访问该程序,然后我可以在那里输入帐户密钥,但如果我必须以另一种方式进行操作,那也可以!我会尝试您所做的更改,并使用带有帐户信息的“正确”json 文件。非常感谢!
    • 很高兴为您提供帮助,您可以使用ENV variables 将密钥传递给容器,但您必须编写一些 bash 来读取 ENV 并放置到 json。如果正确,请标记为答案。
    • 所以我现在可以生成安装密钥,并且我已经将它添加到我的容器中(刚刚安装了 nano 并粘贴它进行测试),但我认为它还没有工作。我不确定在首次启动程序之前是否需要存在安装密钥。我有一个可用的 install.json 文件,并且我已经编辑了我的第一篇文章以包含它。 (我是从 JedEdge 支持团队那里得到的)
    • 我想要一些有关如何使用 ENV 变量添加 installID 的帮助。我在想我可以拥有一个包含所有不同客户安装 ID 的 ENV 文件,并在我将用来创建容器的最终 docker compose 文件中调用 env。我还更新了 dockerfile 和 supervisord.conf 文件以匹配您的更改并添加其他 2 个服务。
    • 创建(并复制到映像)startup.sh 文件,您可以在其中 1. 将代码写入 replace ENV into file 和 2. 启动 supervisord。然后将 CMD 替换为CMD ['/whatever/startup.sh']
    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 2017-02-19
    • 2019-08-21
    • 1970-01-01
    • 2021-03-30
    • 2016-07-14
    • 1970-01-01
    相关资源
    最近更新 更多