Joey Coder
Joey Coder

Reputation: 3489

Docker compose & docker-entrypoint

When running docker-compose up --build I am always running into this error message. Anyone knows what I am doing wrong with the docker-entrypoint file?

ERROR: for 986991ccdfe1_ubercoach_web_1  Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./docker-entrypoint.sh\": permission denied": unknown

ERROR: for web  Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./docker-entrypoint.sh\": permission denied": unknown
ERROR: Encountered errors while bringing up the project.

docker-compose:

version: '3'

services:
  db:
    image: postgres
    ports:
      - "5432:5432"
  web:
    build: .
    entrypoint: ./docker-entrypoint.sh
    env_file: .env
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

Dockerfile:

# Pull base image FROM python:3

# Set environment varibles
ENV PYTHONUNBUFFERED 1

# Set work directory
RUN mkdir /code
WORKDIR /code

# Install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /code/Pipfile
RUN pipenv install --deploy --system --skip-lock --dev

# Copy project
COPY . /code/

docker-entrypoint.sh

#!/bin/bash

# Collect static files
echo "Collect static files"
python manage.py collectstatic --noinput

# Apply database migrations
echo "Apply database migrations"
python manage.py migrate

# Start server
echo "Starting server"
python manage.py runserver 0.0.0.0:8000

Upvotes: 43

Views: 225411

Answers (5)

hjsimpson
hjsimpson

Reputation: 1216

"./docker-entrypoint.sh": permission denied": unknown

I would guess your docker-entrypoint.sh doesn't have execute permissions (x). But also docker-compose.yml is not really the best place for the docker-entrypoint.sh. It's the override setting, see entrypoint. The default should go in the Dockerfile. Try this:

Add this to the end of your Dockerfile

COPY --chmod=0755 ./docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

The docker-entrypoint.sh should be in the same folder as the Dockerfile (or adjust the COPY path). Remove the entrypoint line from your docker-compose.yml. Rebuild, rerun.

Upvotes: 39

Emre
Emre

Reputation: 370

The solution was little bit different for me. First of all I needed to give a reference of the entrypointfile to the docker-compose.My dockerfile, docker-compose and entrypoint file stays all in a directory called docker, so

services:
  app:
    build:
      context: ..
      dockerfile: docker/Dockerfile.development
    entrypoint: docker/development-entrypoint.sh
    ports:
      - 3000:3000
    env_file:
      - ../.env.development
    depends_on:
      - postgres

I need to also change the execute right of the entrypoint and I did this in the dockerfile like this.

RUN chmod 755 docker/entrypoint.sh

The most annoying part was the .sh file. Normally by many different linux systems, you would start the .sh file as this

#!/bin/bash

Basicly, in one linux system, you use different shells.In .sh files, in order to define which shell you want to use, you start the file as show. But for me it did not work, since I was using node alpine image, and when I checked, there was no bash at all, so I had to chagne it to this.

#!/bin/sh

Hope it helps you or anyone who is having problem with this!

Upvotes: 10

MrMahdi313
MrMahdi313

Reputation: 89

you should copy entrypoint like this:

docker-compose:

version: '3'

services:
  db:
    image: postgres
    ports:
      - "5432:5432"
  web:
    build: .
    entrypoint: /docker-entrypoint.sh
    env_file: .env
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

Dockerfile:

# Pull base image FROM python:3

# Set environment varibles
ENV PYTHONUNBUFFERED 1

# Set work directory
RUN mkdir /code
WORKDIR /code

# Install dependencies
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /code/Pipfile
RUN pipenv install --deploy --system --skip-lock --dev

# Copy project
COPY . /code/

Upvotes: 7

Elcin Guseynov
Elcin Guseynov

Reputation: 535

You may add "bash" in Entrypoint:

ENTRYPOINT ["bash","docker-entrypoint.sh"]

Upvotes: 4

thierno
thierno

Reputation: 934

I spent a lot of time on this issue. the problem is that due the volume on the web service. I got the issue, because, I was docker-machine to deploy my app. Docker is using is using the volume which it does not find in the remote machine. Run the following to erase containers and volumes, which is the simple way to get rid of the issue.

docker-compose down -v

NB: Be cautious with the above command. Because, it delete all volume, therefore all the data you have on them.

The solution I use consists of docker a different docker-file and not adding volume to the web service.

Upvotes: 3

Related Questions