Docker compose & docker-entrypoint – Docker

Photo of author
Written By M Ibrahim
boot2docker docker-compose

Quick Fix: To fix the permission denied error when running docker-compose, ensure that the "docker-entrypoint.sh" has execute permissions. Additionally, avoid specifying the entrypoint in "docker-compose.yml". Instead, add the entrypoint to the "Dockerfile", including the COPY and RUN commands to copy and set execute permissions. Remember to remove the entrypoint from the "docker-compose.yml" file before rebuilding and rerunning the container.

The Solutions:

Solution 1: Adjusted Default Entrypoint

The error message indicates that the docker-entrypoint.sh file doesn’t have execute permissions. Additionally, the default entrypoint should be set in the Dockerfile, not in the docker-compose.yml file.

To resolve this:

  1. Add the following lines to the end of your Dockerfile:

    COPY ./docker-entrypoint.sh /docker-entrypoint.sh
    RUN chmod +x /docker-entrypoint.sh
    ENTRYPOINT ["/docker-entrypoint.sh"]
    
  2. Ensure that the docker-entrypoint.sh file is in the same folder as the Dockerfile or adjust the COPY path.

  3. Remove the entrypoint line from your docker-compose.yml.

  4. Rebuild and rerun the containers.

This will set the default entrypoint in the Dockerfile, grant execute permissions to the docker-entrypoint.sh script, and remove the override setting from docker-compose.yml.

Solution 2: Update Entry Point and Adjust Execution Permissions

Entry Point Reference in docker-compose.yml:

Adjust the docker-compose.yml file to include a reference to the entrypoint file:

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

Adjusting Execution Permissions:

Within the Dockerfile, add a command to modify the execution permissions of the entrypoint script:

RUN chmod 755 docker/entrypoint.sh

Using the Correct Shell in Entrypoint Script:

In the entrypoint script, use the correct shell interpreter directive:

#!/bin/sh

By making these adjustments, the docker-compose command should now successfully build and run the container with the updated entrypoint script.

Solution 4: Use “bash” in Entrypoint

To resolve the “OCI runtime create failed: starting container process caused “exec: “./docker-entrypoint.sh”: permission denied”” error when running “docker-compose up –build,” you can add “bash” to the entrypoint in the Dockerfile. Here’s how:

  1. Open your Dockerfile.
  2. Locate the ENTRYPOINT instruction. It should look something like this:
  3. “`
    ENTRYPOINT [“docker-entrypoint.sh”]
    “`

  4. Modify the ENTRYPOINT instruction to include “bash” as the first element. It should look like this:
  5. “`
    ENTRYPOINT [“bash”, “docker-entrypoint.sh”]
    “`

  6. Save the Dockerfile.
  7. Rebuild the image using the command:
  8. “`
    docker-compose up –build
    “`

By adding “bash” to the entrypoint, you’re specifying that the container should run the “bash” shell and then execute the “docker-entrypoint.sh” script. This grants the necessary permissions to run the script successfully and should resolve the error.