Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run docker image

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

like image 837
John Code Avatar asked Sep 18 '25 02:09

John Code


1 Answers

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

like image 181
nischay goyal Avatar answered Sep 19 '25 16:09

nischay goyal