I have this Dockerfile (steps based on installation guide from AWS)
FROM amazon/aws-cli:latest
RUN yum install python37 -y
RUN curl -O https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py --user
RUN pip3 install awsebcli --upgrade --user
RUN echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
RUN source ~/.bashrc
ENTRYPOINT ["/bin/bash"]
When I build the image with docker build -t eb-cli .
and then run eb --version
inside container docker run -it eb-cli
, everything works
bash-4.2# eb --version
EB CLI 3.20.3 (Python 3.7.1)
But, when I run the command directly as docker run -it eb-cli eb --version
, it gives me this error
/bin/bash: eb: No such file or directory
I think that is problem with bash profiles, but I can't figure it out.
Your sourced
.bashrc
would stay in the layer it was sourced, but won't apply to the resulting container. This is actually more thoroughly explained in this answer:Source: https://stackoverflow.com/a/55213158/2123530
A solution for you would be to set the
PATH
in an environment variable of the container, rather, and blank theENTRYPOINT
as set by your base image.So you could end with an image as simple as:
With this Dockerfile, here is the resulting build and run:
Notes:
python37
--user
flag, is a good practice indeed, but since you are running this command asroot
, there is no real point in doing so, in the end--upgrade
flag does not makes much more sense, here, as the package won't be installed beforehand. And upgrading the package would be as simple as rebuilding the imageRUN
in your Dockerfile is an advisable practice that you can find in the best practice