1

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???

2 Answers 2

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.
0

I've just gone through this issue now on a Windows machine using docker-compose.

To fix it, I simply opened the entryfile.sh in VS Code.

Then, in the bottom right, could see CRFL. Clicked in it and changed to LF (as shown here)

Now it finds the file and works as expected.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.