0

I am setting up a multistage build in Docker where I need to pull some data from a remote image. In that remote image, I see they installed the AWS CLI using the following set of commands in order to get it into an Alpine-based image:

RUN apk --no-cache add python3 && \
    pip3 install awscli && \
    aws --version

The copy say it's just fine

COPY --from=remote_setup /usr/bin/terraform /usr/bin/terraform
COPY --from=remove_setup /usr/bin/aws /usr/bin/aws

Terraform here runs peachy, but AWS does not. The output looks like this:

/ # terraform -v
Terraform v0.12.2

/ # ls -lh /usr/bin | grep aws
-rwxr-xr-x    1 root     root         817 Jun 19 19:51 aws
/ # aws --version
/bin/sh: aws: not found

If I add python3, I then get this error:

/ # aws --version
Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in <module>
    import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'

Is there a trick to copying over all the data from a command in that particular layer to my new one or for simplicity's sake should I just install Python and the AWS CLI myself in my image?

Thanks!

el n00b
  • 1,957
  • 7
  • 37
  • 64
  • Can't you install the python and awscli instead? Installing will make sure that it downloads all the dependencies and set up the required configurations. – Vineet Palan Jun 19 '19 at 21:20

1 Answers1

0

pip is the standard Python package manager. In addition to installing a wrapper script in /usr/bin (or the current environment's bin directory) it also installs a fair bit of library code under a .../lib/pythonX.Y/site-packages/... tree. Also, packages are allowed to depend on other packages, so it's not going to just be a single directory in the site-packages directory.

In short: you will need the Python interpreter and everything the pip install installs, so you should run that command yourself in your derived image.

David Maze
  • 130,717
  • 29
  • 175
  • 215