You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Docker运行带环境与全局JSON的Newman?已遇命令报错

How to Pass Local Test/Environment/Global JSON Files to Newman in Docker

The error you're seeing happens because Docker containers can't directly access files on your host machine by default. When you used paths like ~/environments/staging.json in your original command, the Newman instance inside the container had no idea where that directory was—those paths only exist on your local system, not inside the Ubuntu 14.04 container.

Here's how to fix this properly using volume mounts (-v flag) to share your local files with the container, and then reference the container-side paths in your Newman command:

Step 1: Understand Volume Mounts

The -v flag lets you map a directory/file from your host machine to a path inside the container. Think of it as creating a shared folder between your local system and the container.

Step 2: Updated Docker Run Command

Let's assume your files are located at these local paths:

  • tests.json in your current working directory
  • staging.json in ~/environments
  • globals.json in ~/data

Use this command to mount each local directory to a container directory, then use the container paths in Newman:

sudo docker run -it --name newman \
  -v $(pwd):/tests \
  -v ~/environments:/envs \
  -v ~/data:/globals \
  postman/newman_ubuntu1404 \
  newman run /tests/tests.json \
  --environment /envs/staging.json \
  -n 1 \
  --globals /globals/globals.json

Breakdown of the command:

  • -v $(pwd):/tests: Maps your current local directory (where tests.json lives) to /tests inside the container
  • -v ~/environments:/envs: Maps your local ~/environments directory to /envs inside the container
  • -v ~/data:/globals: Maps your local ~/data directory to /globals inside the container
  • The Newman command now uses the container-side paths (/tests/tests.json, /envs/staging.json, etc.) which Newman can access directly.

Step 3: Simplify with a Single Shared Directory

If you want to clean things up, move all your Newman-related files (tests, environments, globals) into one local directory (e.g., ~/postman-files). Then you only need one volume mount:

sudo docker run -it --name newman \
  -v ~/postman-files:/postman \
  postman/newman_ubuntu1404 \
  newman run /postman/tests.json \
  --environment /postman/staging.json \
  -n 1 \
  --globals /postman/globals.json

Bonus: Auto-Clean Up the Container

Add the --rm flag to automatically delete the container after it finishes running (avoids cluttering your system with unused containers):

sudo docker run -it --rm \
  -v $(pwd):/tests \
  -v ~/environments:/envs \
  -v ~/data:/globals \
  postman/newman_ubuntu1404 \
  newman run /tests/tests.json \
  --environment /envs/staging.json \
  -n 1 \
  --globals /globals/globals.json

This should resolve the "Invalid command or parameter" error, as Newman will now be able to find all the required JSON files inside the container.

内容的提问来源于stack exchange,提问作者QA Prof

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:03:23