I have a Docker image that I can run with no problems on my local machine but when I try to run it in a Kubernetes cluster the container fails to start because it can't execute the start up command for the app.
I'm copying the dist directory over because that is where I packaged my app. If I wanted to run it locally all I need to do is run ./dist/bin/start and then the app would start. This is the structure of the directory.
dist/
├── bin
│   └── start
├── conf
│   ├── application.conf
│   ├── routes
│   └── secure.conf
├── my-play-framework-api-0.1.0-SNAPSHOT
└── libThis is the Dockerfile that I am using.
FROM openjdk:11-jre-slim
COPY dist /dist
EXPOSE 9000 9443
WORKDIR /dist
CMD ["/dist/bin/start","-Dhttps.port=9443"]I can build and run this image using the docker run command.
The problems start appearing when I pull this image from the Gitlab registry from my Kubernetes cluster. The image pulls successfully according the output when I describe the Pod that the container is running in. It seems like that container is not starting because it can't locate the /dist directory even after I copied it in the Dockerfile.
Events:
  Type     Reason     Age                  From                                                    Message
  ----     ------     ----                 ----                                                    -------
  Normal   Scheduled  12m                  default-scheduler                                       Successfully assigned <REDACTED>/<REDACTED>-<REDACTED> to <REDACTED>.eu-central-1.compute.internal
  Normal   Pulled     11m (x5 over 12m)    kubelet, <REDACTED>.eu-central-1.compute.internal  Successfully pulled image "<REDACTED>/<REDACTED>/<REDACTED>/<REDACTED>"
  Normal   Created    11m (x5 over 12m)    kubelet, <REDACTED>.eu-central-1.compute.internal  Created container
  Warning  Failed     11m (x5 over 12m)    kubelet, <REDACTED>.eu-central-1.compute.internal  Error: failed to start container "<REDACTED>": Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/dist/bin/start\": stat /dist/bin/start: no such file or directory": unknown
  Normal   Pulling    10m (x6 over 12m)    kubelet, <REDACTED>.eu-central-1.compute.internal  pulling image "registry.gitlab.com/<REDACTED>/<REDACTED>/<REDACTED>"
  Warning  BackOff    119s (x44 over 11m)  kubelet, <REDACTED>.eu-central-1.compute.internal  Back-off restarting failed containerIs there something that I am missing here?
Maybe you need to fix your Dockerfile , and pay attention to the order of Docker instructions and some best practices.
FROM openjdk:11-jre-slim
WORKDIR /dist
COPY dist/* .
EXPOSE 9000 9443
CMD ["/dist/bin/start","-Dhttps.port=9443"]And first locally test this and make sure the required directory structure exists inside by execing into the container and do an ls