Reputation: 675
First, sorry if my question sounds too easy or silly. I'm new to docker. I have created my docker image and passed several jar files which are to be run immediately when the container starts. I want to run the script "serve.sh" immediately when the container starts I succeeded in creating the images well, but when I run the container, it throws me this error:
C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-it\": executable file not found in $PATH": unknown.
Here is the command I use to run the image I craeted:
docker run b24b37614e1a -it
Here is my docker file:
FROM openjdk:8-jdk-alpine
EXPOSE 8080:8080
COPY apigateway-0.0.1-SNAPSHOT.jar apigateway.jar
COPY authservice-0.0.1-SNAPSHOT.jar authservice.jar
COPY institutionsservice-0.0.1-SNAPSHOT.jar institutionsservice.jar
COPY messagesservice-0.0.1-SNAPSHOT.jar messagesservice.jar
COPY postsservice-0.0.1-SNAPSHOT.jar postsservice.jar
COPY userservice-0.0.1-SNAPSHOT.jar userservice.jar
COPY serve.sh serve.sh
CMD [ "bash" "./serve.sh" ]
Please what am I doing wrong ? I'm new to docker
Upvotes: 4
Views: 5725
Reputation: 101
docker run -it
then args (c/o Luca Fabbian)bash
. Use sh
. (c/o MC Emperor)CMD ["sh", "./serve.sh"]
CMD ./serve.sh
CMD ["./serve.sh"]
This assumes you already took Luca's advice:
Keep in mind that docker args order matters: you wrote docker run b24b37614e1a -it which is different from docker run -it b24b37614e1a
bash
.I pulled the openjdk:8-jdk-alpine
image to confirm, and it does not come with bash. Alpine images come with sh
so the code provided will never work unless you correct the shell used or install bash.
From your response to nischay:
I get this error: "sh: ./serve.sh: unknown operand"
I updated My CMD instruction to: CMD [ "bin/bash" "./serve.sh" ]
CMD in the exec form takes an array of instructions. These must be separated by a comma.
Do this:
CMD [ "executable", "param1" ]
^
As nischay said, there are a few different ways to use CMD to do roughly the same thing, from the reference quoted.
You can in fact use the exec form of CMD to say things like:
CMD [ "sh", "./serve.sh" ]
Typing out /bin/sh
or /bin/bash
or whichever shell you want is not required unless desired. But if you don't need the shell, you can use exec form without the shell as well:
CMD [ "./serve.sh" ]
Upvotes: 0
Reputation: 3480
There are a couple of things which you should correct, First one is the CMD
format which should be
CMD instruction has three forms:
CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)
CMD [ "/bin/bash" , "./serve.sh" ]
Another thing, When you do docker run
, the instructions are
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
which means all the options has to be before IMAGE
and in your case it
is appearing after IMAGE
.
The correct command should be
docker run -it b24b37614e1a
BTW, small question, why you want to run an interactive container of this application. Ideally, it should be something like
docker run -p $HOST_PORT:$APP_PORT b24b37614e1a
-p
=> Publish a container's port(s) to the host
and then you can access your application localhost:$HOST_PORT
or machine_IP:$HOST_PORT
Upvotes: 4
Reputation: 215
Keep in mind that docker args order matters:
you wrote docker run b24b37614e1a -it
which is different from
docker run -it b24b37614e1a
Hope it solves your problem :)
Upvotes: 3