Docker entrypoint script on ECS, Permission Denied

Viewed 287

Im looking at a problem when i deploy to AWS ECS regarding permissions.

I need to start a shell script in the entrypoint of the Dockerfile, which uses wait-for-it.sh to pause until the supporting container is ready.

The base for the project is aspnet core and is intended to facilitate database upgrades.

The error from the container is:

container_linux.go:380: starting container process caused: exec: "./docker-entrypoint.sh": permission denied

Other posts suggest its because the scripts arnt marked as executable. See below build output which confirms this is done

Step 14/21 : WORKDIR /app
 ---> Running in 5517aabffaa2
Removing intermediate container 5517aabffaa2
 ---> 9724951dd81b
Step 15/21 : COPY Data.Migrator/wait-for-it.sh wait-for-it.sh
 ---> dcd710cf0671
Step 16/21 : RUN chmod +x wait-for-it.sh
 ---> Running in 914a4e63fbcd
Removing intermediate container 914a4e63fbcd
 ---> d1e8da150a8c
Step 17/21 : COPY ["Data.Migrator/docker-entrypoint.sh", "docker-entrypoint.sh"]
 ---> 1e193d79558c
Step 18/21 : RUN ["chmod", "+x", "docker-entrypoint.sh"]
 ---> Running in fb737194fcc3
Removing intermediate container fb737194fcc3
 ---> e89b9eaa086c
Step 19/21 : COPY --from=publish /app/publish .
 ---> 972f1bd340ec
Step 20/21 : ENTRYPOINT ["./docker-entrypoint.sh"]
 ---> Running in 19469ffcfb32
Removing intermediate container 19469ffcfb32
 ---> 00447053022c

My service in the docker-compose is

  data_migrator:
    image: xxx.dkr.ecr.eu-west-1.amazonaws.com/migrator:latest
    restart: 'always'
    depends_on:
      sql-server-db:
        condition: service_healthy
    environment:
      MAIN_STORE_CONNECTION_STRING: "Server=sql_server_db,1433;Database=MainStore;User Id=sa;Password=Password123@;MultipleActiveResultSets=True;"
      SIGNABLE_STORE_CONNECTION_STRING: "Server=sql_server_db,1433;Database=SignableStore;User Id=sa;Password=Password123@;MultipleActiveResultSets=True;"
      DEPENDSUPON_HOST: sql-server-db
      DEPENDSUPON_PORT: 1433
      ECS_IMAGE_PULL_BEHAVIOR: always
    networks:
      - publicnet

Docker entrypoint script

#!/bin/bash

# Abort on any error (including if wait-for-it fails).
set -e

# Wait for the backend to be up, if we know where it is.
if [ -n "$DEPENDSUPON_HOST" ]; then
  echo "Waiting for database connection..."
  ./wait-for-it.sh "$DEPENDSUPON_HOST:${DEPENDSUPON_PORT:-6000}"
fi

# Run the main container command.
exec "$@"

and the dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Data.Migrator/Data.Migrator.csproj", "Data.Migrator/"]
COPY ["Web.Workflow/Web.Workflow.csproj", "Web.Workflow/"]
RUN dotnet restore "Data.Migrator/Data.Migrator.csproj"
COPY . .
WORKDIR "/src/Data.Migrator"
RUN dotnet build "Data.Migrator.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Data.Migrator.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app

# Copy wait-for-it.sh into our image
COPY Data.Migrator/wait-for-it.sh wait-for-it.sh
# Make it executable, in Linux
RUN chmod +x wait-for-it.sh

COPY ["Data.Migrator/docker-entrypoint.sh", "docker-entrypoint.sh"]
RUN ["chmod", "755", "docker-entrypoint.sh"]
# Make it executable, in Linux
COPY --from=publish /app/publish .
ENTRYPOINT ["./docker-entrypoint.sh"]

CMD ["dotnet", "Data.Migrator.dll"]
0 Answers
Related