简体   繁体   English

Docker:带有参数和引号的入口点

[英]Docker: Entrypoint with arguments and quotes

I'm trying to create a Docker image with an entrypoint.sh and pass arguments when I run the Docker, the issue is when I want to use arguments with double quotes. 我正在尝试使用entrypoint.sh创建一个Docker映像并在运行Docker时传递参数,问题是当我想使用带双引号的参数时。

I search in many places, also I know is more a Bash question and how the arguments are expanded by the double quotes, but maybe someone has an idea how to avoid this. 我在很多地方进行搜索,我还知道更多是一个Bash问题以及双引号如何扩展参数,但是也许有人对如何避免这种情况有所了解。

My Dockerfile : 我的Dockerfile

FROM centos:7

COPY    entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

My entrypoint.sh : 我的entrypoint.sh

#!/bin/bash

command --display=true "$@"

Running the Docker: 运行Docker:

docker run -ti docker-image:latest --driver="kernel-4.0 kernel-4.1"

Expected behaviour: 预期的行为:

command --display=true --driver="kernel-4.0 kernel-4.1"

Actual behaviour: 实际行为:

command --display=true --driver=kernel-4.0 kernel-4.1

I tried escaping the double quotes but nothing. 我试图转义双引号,但什么也没有。

Did you try to escape \\ before the value? 您是否试图在值之前转义\\ It's working with me. 它正在和我一起工作。

#!/bin/bash
echo "all params $@"
command --display=true "$@"

and

docker run -ti yourimage --driver=\"kernel-4.0 kernel-4.1\"

As mentioned by @David, this the expected behabout of bash script. 如@David所提到的,这是bash脚本的预期行为。

if you run entrypoint.sh outside of Docker, it will skip quotes. 如果您在Docker外部运行entrypoint.sh ,它将跳过引号。

./entrypoint.sh --driver="kernel-4.0 kernel-4.1"

#output

all params --driver=kernel-4.0 kernel-4.1
--display=true --driver=kernel-4.0 kernel-4.1

How to keep quotes in Bash arguments? 如何在Bash参数中保留引号?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM