我正在使用 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
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
从 jenkinsci/jnlp-slave:4.3-1
执行命令?答案 0 :(得分:0)
每个图像都有一个 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>
选项。例如,要在 jenkins 图像中运行 cat /etc/os-release
,您可以试试这个:
docker run --rm --entrypoint="" jenkinsci/jnlp-slave:4.3-1 cat /etc/os-release
也准备好接受一些图像除了应用程序的一个二进制文件之外什么都没有。在此类图像中,您不会找到 sh
、ls
、cat
等。