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.
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.
My Dockerfile
:
FROM centos:7
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
My entrypoint.sh
:
#!/bin/bash
command --display=true "$@"
Running the 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.
if you run entrypoint.sh
outside of Docker, it will skip quotes.
./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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.