Search code examples
windowsamazon-web-servicesdockerdockerfile

Docker entrypoint.sh not found


Following the instructions as outlined to deploy Duo CloudMapper to AWS environment and getting an error

Docker File

FROM python:3.7-slim as cloudmapper

LABEL maintainer="https://github.com/0xdabbad00/"
LABEL Project="https://github.com/duo-labs/cloudmapper"

WORKDIR /opt/cloudmapper
ENV AWS_DEFAULT_REGION=us-east-1 

RUN apt-get update -y
RUN apt-get install -y build-essential autoconf automake libtool python3.7-dev python3-tk jq awscli

COPY cloudmapper/. /opt/cloudmapper
COPY entrypoint.sh /opt/cloudmapper/entrypoint.sh

# Remove the demo data
RUN rm -rf /opt/cloudmapper/account-data/demo

# Install the python libraries needed for CloudMapper
RUN cd /opt/cloudmapper && pip install -r requirements.txt


ENTRYPOINT /opt/cloudmapper/entrypoint.sh

Now building the docker image

C:\> docker build -t cloudmapper .

When I run the docker using the below command I get an error

C:/> docker run -t cloudmapper

Error

/bin/sh: 1: /opt/cloudmapper/entrypoint.sh: not found

Verified that the file exists in the appropriate location screenshot attached

Using Docker on Windows 10

Image in the dockerfile is python:3.7-slim


Solution

  • Assuming the images are removed and replaced with text and the question doesn't get closed.

    bash can return "file not found" when

    • the entrypoint shell script is not marked executable for the current user
    • the hash bang in the entrypoint shell script points to a binary that does not exist
    • the shell script actually does not exist.

    You can fix the first problem by ensuring you use the new --chmod flag to ensure the executable bit is set. Even if the user is root it is necessary that there is at least 1 executable bit set.

    COPY --chmod=0755 *.sh /opt/cloudmapper/
    ENTRYPOINT ["/opt/cloudmapper/entrypoint.sh"]
    

    ps. This integrated COPY --chmod only works with buildkit enabled builds, so you might need to force buildkit, or split the chmod into a separate explicit RUN step.

    The 2nd issue can be dealt with by ensuring the first line of entrypoint.sh uses sh rather than bash if you are using a lightweight base image like alpine:

    #!/bin/sh
    set -e
    # etc
    

    Also, if on Windows especially, ensure ALL files, especially the entrypoint .sh file, are set to utf-8 encoding with lf style line endings. As linux doesn't understand the cr, it will try to execute /bin/sh<cr> as the shell which clearly doesn't exist.

    In terms of the file not existing, verify the entrypoint.sh is being copied into a location that is referenced by env.PATH, or that the entry point directive uses a fully qualified path.

    --
    edited to add cr-lf revelation.