Arif Oyong
Arif Oyong

Reputation: 432

Docker-compose "exec: \"/usr/src/app/entrypoint.sh\": permission denied"

This is based on https://testdriven.io/courses/microservices-with-docker-flask-and-react/

I'm running a docker file that will point to entrypoint.sh.

The docker-compose-f docker-compose-dev.yml build run successfully But running docker-compose-f docker-compose-dev.yml up shows

ERROR: for users  Cannot start service users: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/usr/src/app/entrypoint.sh\": permission denied": unknown
ERROR: Encountered errors while bringing up the project.

I did try to run on interactive mode with docker run -it –tty users_app:latest sh. Running ./entrypoint.sh did work. But it didn't work with docker-compose.

Does anybody have the same issue?

This is my docker-compose-dev.yml, Dockerfile-dev, and entrypoint.sh

docker-compose-dev.yml

version: '3.6'

services:
  users:
    build:
      context: ./services/users
      dockerfile: Dockerfile-dev
    volumes:
      - './services/users:/usr/src/app'
    ports:
      - 5001:5000
    environment:
      - FLASK_APP=project/__init__.py
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev
      - DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test    
    depends_on:
      - users-db

  users-db:  
    build:
      context: ./services/users/project/db
      dockerfile: Dockerfile
    ports:
      - 5435:5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

Dockerfile-dev

# base image
FROM python:3.6.5-alpine

# install dependencies
RUN apk update && \
    apk add --virtual build-deps gcc python-dev musl-dev && \
    apk add postgresql-dev && \
    apk add netcat-openbsd

# set working directory
WORKDIR /usr/src/app

# add and install requirements
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# add app
COPY . /usr/src/app

# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh

# run server
#USER root
#RUN ["chmod", "+x", "/usr/src/app/entrypoint.sh"]
CMD ["/usr/src/app/entrypoint.sh"]

entrypoint.sh

#!/bin/sh

echo "Waiting for postgres..."
while ! nc -z users-db 5432; do
    sleep 0.1
done

echo "PostgresSQL started"

python manage.py run -h 0.0.0.0

Upvotes: 5

Views: 7108

Answers (3)

esasiela
esasiela

Reputation: 11

If you are developing on a windows box, then it could be a line terminator issue. When bash runs your script, it does not handle the windows style /r/n line terminators.

Try running this locally on your windows dev box... dos2unix entrypoint.sh

This will change the line terminators to unix style. Then rebuild the container. This cleared up the problem for me.

Upvotes: 1

hakuna matata
hakuna matata

Reputation: 71

Check the permission of entrypoint.sh in host computer, cause it would copy everything to container.

chmod +x ./entrypoint.sh

Then rebuild.

Upvotes: 7

Arif Oyong
Arif Oyong

Reputation: 432

Running the chmod +x /usr/src/entrypoint.sh in the source directory does work.
Docker is it's own system file, but it copies everything (including permission) from the source directory.

However, i couldn't understand, why running the RUN chmod +x /usr/src/app/entrypoint.sh in the dockerfile doesn't work

Upvotes: 12

Related Questions