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.
CodePudding user response:
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:
Each command runs a separate sub-shell, so the environment variables are not preserved and
.bashrc
is not sourced
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 the ENTRYPOINT
as set by your base image.
So you could end with an image as simple as:
FROM amazon/aws-cli:latest
ENV PATH="/root/.local/bin:${PATH}"
RUN yum install python37 -y \
&& pip3 install awsebcli
ENTRYPOINT [""]
With this Dockerfile, here is the resulting build and run:
$ docker build . -t eb-cli -q
sha256:49c376d98fc2b35cf121b43dbaa96caf9e775b0cd236c1b76932e25c60b231bc
$ docker run eb-cli eb --version
EB CLI 3.20.3 (Python 3.7.1)
Notes:
- you can install the really latest version of pip, as you did it, but it is not needed as it is already bundled in the package
python37
- installing packages for the user, with the
--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 - having the
--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 image - Reducing the number of layer of an image by reducing the number of
RUN
in your Dockerfile is an advisable practice that you can find in the best practice
CodePudding user response:
Can you post below two commands output from inside of the container:
which eb
echo $PATH