Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker compose how to mount entrypoint and then use it

I have a service in the docker compose as follows.

  nginx:
    image: nginx:1.18.0-alpine
    ports:
      - 8000:80
    volumes:
      - ./nginx/localhost/conf.d:/etc/nginx/conf.d
      - ./entrypoint.sh:/entrypoint.sh
    entrypoint: ./entrypoint.sh
    depends_on:
      - webapp
    networks:
      - nginx_network

I get the error

Cannot start service nginx: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/entrypoint.sh": permission denied: unknown

ERROR: for nginx  Cannot start service nginx: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/entrypoint.sh": permission denied: unknown            
ERROR: Encountered errors while bringing up the project.   

How can i do this

like image 553
Santhosh Avatar asked Dec 04 '25 06:12

Santhosh


2 Answers

I have to use ["/bin/sh","/entrypoint.sh"]

  nginx:
    image: nginx:1.18.0-alpine
    ports:
      - 8000:80
    volumes:
      - ./nginx/localhost/conf.d:/etc/nginx/conf.d
      - ./entrypoint.sh:/entrypoint.sh
    entrypoint: ["/bin/sh","/entrypoint.sh"]
    depends_on:
      - webapp
    networks:
      - nginx_network
like image 60
Santhosh Avatar answered Dec 06 '25 20:12

Santhosh


I don't have enough information about your entrypoint script, config file and the web app minimal information.

Sometimes when you create a file on your host machine it lacks some permissions to be executed by some users in your docker container, so Iwould think about checking the permissions for that file by running:

ls -l

that will give you all permissions about that file, and maybe that's why it's telling you permission is denied try adding execution permission running chmod +x ./entrypoint.sh.

I usually do that using a dockerfile when working on a script from my context.

dockerfile

FROM nginx:1.18.0-alpine

COPY /entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT [ "./entrypoint.sh" ]: 

docker-compose.yaml

version: "3.8"
services:
  nginx:
    build:
      context: ./    
    ports:
      - 8000:80
    volumes:
      - ./nginx/localhost/conf.d:/etc/nginx/conf.d
    depends_on:
      - webapp
    networks:
      - nginx_network

Then try to run:

docker-compose up --build

make sure both files are in the same directory.

like image 43
Affes Salem Avatar answered Dec 06 '25 18:12

Affes Salem