I am running the command below in docker file.
CMD [“ bash”, GITHUB_KEY=“######” GITHUB_SECRET=“##########” ./script/server]
When I run it, I get this error message /bin/sh" 1: Syntax error: Unterminated quoted string
You need to have every parameter surrounded by quotes in the CMD instruction.
CMD ["bash", "GITHUB_KEY='######'", "GITHUB_SECRET='##########'", "./script/server"]
Related
My dockerfile looks as below:
FROM ubuntu
ENTRYPOINT echo
CMD ["helloworld"]
The container built from the above dockerfile image is giving a blank output.
[root#dockerhost dproj]# docker run -it --name con1 demo
[root#dockerhost dproj]#
Expected Output:
helloworld
From https://docs.docker.com/engine/reference/builder/#entrypoint :
The shell form:
ENTRYPOINT command param1 param2
The shell form prevents any CMD or run command line arguments from being used, but has the disadvantage that your ENTRYPOINT will be started as a subcommand of /bin/sh -c
From man sh:
-c Read commands from the command_string operand. Set the value of special parameter 0 (see Section 2.5.2, Special Parameters) from the
value of the command_name operand and the positional parameters ($1, $2, and so on) in sequence from the remaining argument operands.
No commands shall be read from the standard input.
/bin/sh -c echo helloworld should assign helloworld to shells $0 and execute echo, which will output an empty line.
I.e. ENTRYPOINT ["echo"] is not ENTRYPOINT echo.
My Dockerfile:
FROM my-image-base
COPY src src
RUN chmod +x src/script.sh
ENTRYPOINT ['/src/script.sh']
After successful build:
docker run created_image
/bin/sh: [/src/script.sh]: No such file or directory
docker run --entrypoint /src/script.sh created_image
script runs successfully
I feel like I'm overwriting the default ENTRYPOINT with the same thing but it behaves differently. Am I misunderstanding something?
No, it's not the same thing, because your ENTRYPOINT is invalid.
ENTRYPOINT has two forms:
The shell command form:
ENTRYPOINT command param1 param2
and the exec form:
ENTRYPOINT ["executable", "param1", "param2"]
Which of the two forms are you using here? If you answer "the second", you have been subtly led astray, because you have single-quotes ' there instead of double-quotes "!
As specified in the docs:
Note: The exec form is parsed as a JSON array, which means that you must use double-quotes (") around words not single-quotes (').
So, you actually have the first form, the shell command form.
Docker will pass your "command" to the shell, like this:
/bin/sh -c "['/src/script.sh']"
Due to the way quotes work when parsing shell command lines, this ends up being equivalent to typing [/src/script.sh] into your shell. The shell then rightfully complains that that's not a valid command.
# cat Dockerfile
FROM golang:1.10
WORKDIR /go/src/app
COPY source .
RUN go install -v
ENTRYPOINT [“app”,”-single=true”,”-port=8080"]
# docker run -p 8080:8080 valkyrie-app:v0.0.1
/bin/sh: 1: Syntax error: Unterminated quoted string
Getting this error while running docker run but docker build was successfull, can you please suggest on this error?
#docker build -t valkyrie-app:v0.0.1 .
.....
Successfully built d9ad881d0278
Successfully tagged valkyrie-app:v0.0.1
“ and ” are not valid JSON quotes. Only " is a legitimate quote, in either JSON or POSIX sh.
Thus, your RUN command is not valid JSON, so it's being parsed as a shell command (with only one valid double-quote character instead of matched pairs, hence the specific error seen).
If you're on MacOS, see How to Disable Smart Quotes on Ask Different.
I am running through a Docker tutorial, and the Dockerfile contains the following line:
CMD /usr/games/fortune -a | cowsay
When using hadolint to lint the file, I get this recommendation:
DL3025 Use arguments JSON notation for CMD and ENTRYPOINT arguments
So I update the CMD line with JSON notation for the arguments:
CMD ["/usr/games/fortune", "-a", "|", "cowsay"]
Now, after I (re)build the image and run it, I get this error:
(null)/|: No such file or directory
What is the correct way to use proper JSON notation syntax when I need to pipe output from one command to another on a CMD line?
| is a shell symbol which only works within a shell environment.
CMD command param1 param2 (shell form)
This will work as follows: CMD [ "sh", "-c", "command param1 param2"].
CMD ["executable", "param1", "param2"] (exec form, this is the preferred form)
This will not invoke a shell, so | will not function.
You may reference something from here.
For your situation, you need to use a shell to leverage | so the correct way could be something like this:
CMD ["bash", "-c", "/usr/games/fortune -a | cowsay"]
I have a really long command line for the default process due to a number of arguments. I think the easiest would be to create a script (for eg.run.sh) and then call this script in your ENTRYPOINT or CMD. I'm wondering if there is a way to make your ENTRYPOINT or CMD multiline (the way we write RUN). For eg.
ENTRYPOINT["/path/myprocess",
"arg1",
"arg2" ]
I was thinking this is a valid syntax since the format is json. However, docker build throws the error
Step 14 : ENTRYPOINT[
Unknown instruction: ENTRYPOINT[
Is there a way I can split the ENTRYPOINT to multiple lines?
It was a typo in the dockerfile. I missed a space between ENTRYPOINT and [. Dockerfile supports multiline ENTRYPOINT and CMD by terminating the line with \, same as RUN. So, in my case it can be
ENTRYPOINT [ "/path/myprocess", \
"arg1", \
"arg2" \
]