创建容器时,我需要启动以下命令
npm run test -g $GREP但是调用docker作为
GREP=upload docker compose up playwright它将打印以下错误
invalid interpolation format for services.playwright.command.[]: "${GREP:+-g}". You may need to escape any $ with another $基本上,当-g变量设置为Basically时,我需要打印GREP
编辑: docker撰写文件playwright部分
playwright:
container_name: playwright
image: playwright:latest
build:
context: ./e2e
dockerfile: Dockerfile
working_dir: /home/playwright
command: ['test', '--', '${GREP:+-g}', '${GREP}']EDIT2:坞文件
FROM mcr.microsoft.com/playwright:v1.25.0-focal
USER pwuser
WORKDIR /home/playwright
COPY package.json package-lock.json ./
RUN npm ci
COPY . ./
ENTRYPOINT ["npm", "run"]
CMD ["test"]发布于 2022-08-23 13:02:35
这更多是一个壳问题,而不是码头问题,所以也许有人有一个更漂亮的解决方案。但是,此示例将修复您的问题:
version: "3.7"
services:
test:
image: alpine
command: sh -c 'if [ ! -z "$VAR" ]; then echo "npm run test -g $VAR"; else echo "npm run test"; fi'# example with variable set
VAR=somevar docker compose up test
# example with variable not set
docker compose up testhttps://stackoverflow.com/questions/73457189
复制相似问题