向image.run()添加命令后Docker ps输出为空的问题
Let's break down your issue step by step, starting with context around your environment and then diving into actionable fixes that should get your Selenoid container running with custom commands.
Environment Context
- Docker Plugin version:
1.1.2 - Jenkins version:
2.0.50727 - Docker Client/Server version:
17.12.0-ce - Host OS: Windows 10 Pro x64
Reproducible Scenarios
- Working Case: When you run the Selenoid image via your Jenkinsfile without adding any custom commands to
image.run(), the container spins up successfully and appears indocker psoutput—no issues here. - Failing Case: As soon as you append a custom command (like
-video-output-dir /output) toimage.run(), the container never gets created at all.docker psreturns empty, meaning the command either fails silently or exits immediately.
Why This Happens
The core issue is almost certainly tied to how the outdated Docker plugin handles command arguments, especially on a Windows host:
- Argument Parsing Bugs: Docker plugin
1.1.2is quite old, and it has known flaws splitting command strings into valid Docker arguments. Passing-video-output-dir /outputas a single string might cause the plugin to send it to Docker as one argument (instead of two separate ones: the flag and its value), which Docker can't interpret correctly. - Windows Path/Quoting Conflicts: Even though Selenoid runs in a Linux container, Jenkins (running on Windows) might mishandle argument escaping or path formatting when passing commands to the Docker daemon.
- Version Compatibility: Docker
17.12.0-ceis newer than the1.1.2plugin, and there are compatibility gaps between older plugin versions and more recent Docker releases.
Fixes to Implement
Here are the most reliable solutions to get your custom commands working:
Pass Arguments as Separate List Items
Instead of passing the command as a single string, split each flag and its value into separate arguments in therun()method. This ensures the plugin parses them correctly. For example:docker.image('aerokube/selenoid').run('-d', '-video-output-dir', '/output')If you need to add more flags (like volume mounts), keep each pair as separate elements:
docker.image('aerokube/selenoid').run( '-d', '-v', 'C:/selenoid/videos:/output', // Windows host path mapped to container /output '-video-output-dir', '/output' )Test the Docker Command Directly
To rule out plugin-specific issues, run the exact Docker command in ashstep in your Jenkinsfile. This will tell you if the command works outside the plugin context:sh "docker run -d aerokube/selenoid -video-output-dir /output"If this works and the container shows up in
docker ps, the problem is definitely with how the plugin is handling the arguments.Upgrade the Docker Plugin
The simplest long-term fix is to upgrade your Docker plugin to a newer stable version. The1.1.2version has dozens of bug fixes related to argument parsing and Windows compatibility in later releases. Upgrading will resolve most of these edge cases automatically.Check for Immediate Container Exits
If the container is created but exits immediately (which is whydocker psdoesn't show it), rundocker ps -ato see stopped containers. Check the logs withdocker logs <container-id>to see if Selenoid is throwing an error about the-video-output-dirflag (like missing permissions or an invalid path).
内容的提问来源于stack exchange,提问作者Maksim Gerasimenko

