skip to Main Content

I am using the AWS Python base image for deploying my project as the docker image for the lambda function. Below is my docker file for installing git in the docker image. Commands ran successfully but when I tried to verify git via CLI it wasn’t found. Below is my docker file code:

FROM public.ecr.aws/lambda/python:3.8

# Install the function's dependencies using file requirements.txt
# from your project folder.

COPY requirements.txt  .

RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"; 
     yum update -y 
     yum install git -y

# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}

ENTRYPOINT ["/bin/bash", "-l", "-c"]

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]

I have used ENTRYPOINT to check via CLI. This is the official documentation where the list of base images can be found. When I checked my image I can see that git is installed.
enter image description here

P.S: I want to use base images only.

How can I fix this issue?

2

Answers


  1. Chosen as BEST ANSWER

    Everything in my Dockerfile was correct except yum update -y command. You don't need this command for Amazon Linux 2 OS. Might be needed to update packages in other Linux flavors.

    P.S: If you want to run as Docker image for Lambda remove ENTRYPOINT line from the Dockerfile code.


  2. In your Dockerfile, Please look at this RUN command:

    RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"; 
         yum update -y 
         yum install git -y
    

    See how you have a semicolon after the first command? That semicolon is key to separating each of the commands. The just splits the text up into multiple lines for readability. The doesn’t do anything regarding actually separating the commands. When this RUN command is interpreted, the characters are going to be stripped out and it is all going to be on one line, like this:

    RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"; yum update -y yum install git -y
    

    So the interpreter is only going to see two commands here, a pip3 install command, and a yum update command. The yum update command is getting some extra arguments of yum install git -y that you didn’t intend to give it, and it appears to be ignoring those, or in any case not failing because of those.

    The semicolon is what tells the interpreter "this is the end of this command, the next text starts a new command". So make sure you have a semicolon between each command:

    RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"; 
         yum update -y ; 
         yum install git -y
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search