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.
P.S: I want to use base images only.
How can I fix this issue?
2
Answers
Everything in my
Dockerfile
was correct exceptyum update -y
command. You don't need this command forAmazon 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.In your
Dockerfile
, Please look at thisRUN
command: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, thecharacters are going to be stripped out and it is all going to be on one line, like this:
So the interpreter is only going to see two commands here, a
pip3 install
command, and ayum update
command. Theyum update
command is getting some extra arguments ofyum 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: