Reputation: 448
How to pass the path of the script file to the CMD
in the Dockerfile?
Here is my Dockerfile
FROM openjdk:8-jdk-alpine as base
EXPOSE 8080
WORKDIR '/app'
COPY run/ .
RUN mvn clean install
FROM openjdk:8-jdk-alpine
WORKDIR '/app'
COPY --from=base /app/data/startup.sh ./startup.sh
RUN ["chmod", "+x", "startup.sh"]
CMD ["startup.sh", "start"]
When I gave CMD ["/app/startup.sh", "start"]
, throws the below error
Cannot start service myapp: OCI runtime create failed:
container_linux.go:367: starting container process caused: exec: "/app/startup.sh": stat
/app/startup.sh: no such file or directory: unknown
The documentation says the path would be relative to the WORKDIR, so I tried passing the scriptname alone as it is now - CMD ["startup.sh", "start"]
which resulted in the below error:
Cannot start service myapp: OCI runtime create failed:
container_linux.go:367: starting container process caused: exec: "service.sh": executable file
not found in $PATH: unknown
The startup.sh is a simple script file with a shebang - #!/bin/sh
Am I missing anything here? I am using docker desktop for windows and get the error when I run docker-compose up
just fyi.
Please share how I can resolve this issue. Thanks
Upvotes: 4
Views: 3978
Reputation: 1399
You are copying the file to /app/data
in this step COPY --from=base /app/data/
So try:
CMD ["/app/data/startup.sh", "start"]
Upvotes: 2