linux - 无法使用 jenkinsci/jnlp-slave:4.3-1 从 docker run 执行命令
问题描述
问题
我正在使用 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
问题
- 我想知道为什么一个简单的 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/"
- 是否可以从
docker run
using执行命令jenkinsci/jnlp-slave:4.3-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=<value>
选项,可以在运行时覆盖默认入口点。例如,要cat /etc/os-release
在 jenkins 映像中运行,您可以尝试以下操作:
docker run --rm --entrypoint="" jenkinsci/jnlp-slave:4.3-1 cat /etc/os-release
也准备好接受一些图像除了应用程序的一个二进制文件之外什么都没有。在此类图像中,您不会找到sh
、ls
、cat
等。
推荐阅读
- powershell - 如何正确使用“压缩存档”?错误消息一直说“路径不存在或不是有效的文件系统路径”
- python - “?”是什么意思?在张量流中?
- javascript - 在 netlify 上部署反应应用程序后 HTTP GET 响应 304 状态错误
- python - 合并数组和绘图
- maven - 无法使用 Maven jar 插件添加资源
- ios - 使用静态变量引用 viewContext 以实现 iOS 9 和 iOS 10 Swift 4 的核心数据
- json - 如何从 json 文件中获取标签并将它们附加到图像
- php - 在 WooCommerce 管理页面中仅显示本地订单
- c# - SemaphoreSlim.WaitAsync 如何允许顺序执行异步函数?
- reactjs - 创建一个抽象逻辑的组件(从现有代码)