Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose running entrypoint script in another directory

I was just wondering how to run a docker-entrypoint script in another directory. For example,

the-service:
   image: the-service
   container_name: the-service
   entrypoint: ./app/the/docker-entrypoint.sh 
   build: ./app/the
   ports:
     - 8080:8080

here I get ERROR: for the-service Cannot start service the-service: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./app/the-service/docker-entrypoint.sh\": stat ./app/the-service/docker-entrypoint.sh: no such file or directory": unknown ERROR: Encountered errors while bringing up the project.

docker-compose version is 2.1. So what is the correct way of running this script?

Thanks

like image 611
riyoz Avatar asked Apr 29 '26 17:04

riyoz


1 Answers

I think I have figured it out. You are using the build option so that the docker image can live inside the docker-compose project. This is a little non-standard, but perfectly OK. Using image is more standard.

The entrypoint is executed after the build, regardless of the position in the docker-compose.yml file. When we write the entrypoint, we are writing a reference to a file in the image not the local file system.

You should probably edit your .app/the/Dockerfile as follows add "COPY docker-entrypoint.sh /" add "ENTRYPOINT ["sh", "/docker-entrypoint.sh"]

Then you can edit your docker-compose.yml by removing the "entrypoint: ./app/the/docker-entrypoint.sh"


OLD ANSWER

Without testing it out myself, I would assume that these would work:

  1. As @B0rn2C0de suggest set the workdir appropriately.
  2. Alternatively, use a relative path to where the WORKDIR actually is
  3. Alternatively, use an absolute path.
like image 104
emory Avatar answered May 02 '26 05:05

emory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!