0

I want to run a container with docker-compose. My dockerfile is installing some stuff and at the end it looks like this:

FROM adoptopenjdk/openjdk16 

...

COPY ./myfiles /mydockerfiles
    
ENTRYPOINT [ "/mydockerfiles/init.sh" ]

My docker compose file looks something like this

version: '3.3'

services:
  myservice:
    build: .
    environment:
      restart: "no"
    ports:
      - 10000:10000
    volumes:
      - type: bind
        source: ./dockerdata
        target: /mydockerfiles
    deploy:
      resources:
        limits:
          memory: 4G
        reservations:
          memory: 4G

Pretty basic stuff so far in my opinion. But for some reason I always get this error:

ERROR: for ... Cannot start service myservice: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/mydockerfiles/init.sh": stat /mydockerfiles/init.sh: no such file or directory: unknown

ERROR: for myservice Cannot start service myservice: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/mydockerfiles/init.sh": stat /mydockerfiles/init.sh: no such file or directory: unknown ERROR: Encountered errors while bringing up the project.

If however I open up a shell into the container and run the script manually it all works fine. Also during the build process if once tried to do a chmod +x on the init.sh-File and no error occured. So why is the file available during building, a manual bash; but not when using docker-compose up. What am I missing???

1 Answer 1

1

You're overwriting the COPY step in the Dockerfile with the volume mount:

    volumes:
      - type: bind
        source: ./dockerdata
        target: /mydockerfiles

Volume mounts act like other Linux filesystem mount commands, the newly mounted filesystem shadows any other files or directories that already existed at that location, and they will not be accessible as long as the mount exists. The semi-exception to this is a new named volume, which docker will initialize on first use to include the contents of the image at that location, before performing the mount.

Therefore, if the init.sh file is not in the host folder ./dockerdata, the entrypoint will not be found. Other potential reasons for a shell script to show a "not found" error include:

  • referencing an interpreter on the first line that doesn't exist in the container, e.g. #!/bin/bash in a container that only provides /bin/sh.
  • including windows linefeeds in the script, which turn /bin/sh into /bin/sh\r, and the binary including the trailing carage return does not exist in the container filesystem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.