【问题标题】:Cannot execute command from docker run using jenkinsci/jnlp-slave:4.3-1无法使用 jenkinsci/jnlp-slave:4.3-1 从 docker run 执行命令
【发布时间】:2021-02-03 05:18:24
【问题描述】:

问题

我正在使用 Docker 镜像jenkinsci/jnlp-slave:4.3-1

我尝试像这样从docker run 执行命令:

docker run --rm jenkinsci/jnlp-slave:4.3-1 cat /etc/os-release

但是,该命令似乎没有以通常的方式执行。 例如上面的命令导致错误:

$docker run --rm jenkinsci/jnlp-slave:4.3-1 cat /etc/os-release
At least one -url option is required.
java -jar agent.jar [options...] <secret key> <agent name>
 -agentLog FILE                        : Local agent error log destination
                                         (overrides workDir)
 -cert VAL                             : Specify additional X.509 encoded PEM
                                         certificates to trust when connecting
                                         to Jenkins root URLs. If starting with
                                         @ then the remainder is assumed to be
                                         the name of the certificate file to
                                         read.
 -credentials USER:PASSWORD            : HTTP BASIC AUTH header to pass in for
                                         making HTTP requests.
 -direct (-directConnection) HOST:PORT : Connect directly to this TCP agent
                                         port, skipping the HTTP(S) connection
                                         parameter download. For example,
                                         "myjenkins:50000".
 -disableHttpsCertValidation           : Ignore SSL validation errors - use as
                                         a last resort only. (default: false)
 -failIfWorkDirIsMissing               : Fails the initialization if the
                                         requested workDir or internalDir are
                                         missing ('false' by default) (default:
                                         false)
 -headless                             : Run agent in headless mode, without
                                         GUI (default: false)
 -help                                 : Show this help message (default: false)
 -instanceIdentity VAL                 : The base64 encoded InstanceIdentity
                                         byte array of the Jenkins master. When
                                         this is set, the agent skips
                                         connecting to an HTTP(S) port for
                                         connection info.
 -internalDir VAL                      : Specifies a name of the internal files
                                         within a working directory ('remoting'
                                         by default) (default: remoting)
 -jar-cache DIR                        : Cache directory that stores jar files
                                         sent from the master
 -loggingConfig FILE                   : Path to the property file with
                                         java.util.logging settings
 -noKeepAlive                          : Disable TCP socket keep alive on
                                         connection to the master. (default:
                                         false)
 -noreconnect                          : If the connection ends, don't retry
                                         and just exit. (default: false)
 -protocols VAL                        : Specify the remoting protocols to
                                         attempt when instanceIdentity is
                                         provided.
 -proxyCredentials USER:PASSWORD       : HTTP BASIC AUTH header to pass in for
                                         making HTTP authenticated proxy
                                         requests.
 -tunnel HOST:PORT                     : Connect to the specified host and
                                         port, instead of connecting directly
                                         to Jenkins. Useful when connection to
                                         Jenkins needs to be tunneled. Can be
                                         also HOST: or :PORT, in which case the
                                         missing portion will be auto-configured
                                         like the default behavior
 -url URL                              : Specify the Jenkins root URLs to
                                         connect to.
 -version                              : Shows the version of the remoting jar
                                         and then exits (default: false)
 -webSocket                            : Make a WebSocket connection to Jenkins
                                         rather than using the TCP port.
                                         (default: false)
 -workDir FILE                         : Declares the working directory of the
                                         remoting instance (stores cache and
                                         logs by default)

预期行为

我尝试过使用不同的图像,例如 ubuntu:21.04

命令以正常方式执行,如下所示:

$docker run --rm ubuntu:21.04 cat /etc/os-release
NAME="Ubuntu"
VERSION="21.04 (Hirsute Hippo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu Hirsute Hippo (development branch)"
VERSION_ID="21.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=hirsute
UBUNTU_CODENAME=hirsute

问题

  1. 我想知道为什么一个简单的 Linux 命令会根据映像生成不同的结果。 命令cat /etc/os-release 在以不同方式执行时运行良好,如下所示:
    $docker run --rm -it jenkinsci/jnlp-slave:4.3-1 /bin/bash
    jenkins@4a7d91e19e3a:~$ cat /etc/os-release
    PRETTY_NAME="Debian GNU/Linux 10 (buster)"
    NAME="Debian GNU/Linux"
    VERSION_ID="10"
    VERSION="10 (buster)"
    VERSION_CODENAME=buster
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
    
  2. 是否可以使用jenkinsci/jnlp-slave:4.3-1 执行来自docker run 的命令?

【问题讨论】:

    标签: linux docker jenkins


    【解决方案1】:

    每张图片都有一个ENTRYPOINT。这是一个在您启动容器时调用的可执行对象(带有可选参数)。您可以使用docker inspect 查找默认入口点值。这是docker.io/jenkinsci/jnlp-slave:4.3-1 图像的入口点:

    "Entrypoint": [
      "jenkins-agent"
    ],
    

    这个是针对 ubuntu 的:

    "Entrypoint": null,
    

    当你使用cat /etc/os-release 命令运行jenkins image 时,你有效地执行了这个命令:

    jenkins-agent cat /etc/os-release
    

    当你在 ubuntu 中这样做时,它是 null + cat /etc/os-release,也就是 cat /etc/os-release。这就是发生错误的原因。

    可以在运行时覆盖默认入口点,为此使用--entrypoint=&lt;value&gt; 选项。例如,要在 jenkins 图像中运行 cat /etc/os-release,您可以试试这个:

    docker run --rm --entrypoint="" jenkinsci/jnlp-slave:4.3-1 cat /etc/os-release
    

    还要准备好接受一些图像除了应用程序的一个二进制文件之外什么都没有。在此类图片中,您将找不到shlscat 等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多