How to install awscli using pip in library/node Docker image
Question:
I’m trying to install awscli
using pip
(as per Amazon’s recommendations) in a custom Docker image that comes FROM library/node:6.11.2
. Here’s a repro:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python
python-pip
python-setuptools
groff
less
&& pip --no-cache-dir install --upgrade awscli
&& apt-get clean
CMD ["/bin/bash"]
However, with the above I’m met with:
no such option: --no-cache-dir
Presumably because I’ve got incorrect versions of Python and/or Pip?
I’m installing Python, Pip, and awscli in a similar way with FROM maven:3.5.0-jdk-8
and there it works just fine. I’m unsure what the relevant differences between the two images are.
Removing said option from my Dockerfile doesn’t do me much good either, because then I’m met with a big pile of different errors, an excerpt here:
Installing collected packages: awscli, PyYAML, docutils, rsa, colorama, botocore, s3transfer, pyasn1, jmespath, python-dateutil, futures, six
Running setup.py install for PyYAML
checking if libyaml is compilable
### ABBREVIATED ###
ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
### ABBREVIATED ###
Bottom line: how do you properly install awscli
in library/node:6.x
based images?
Answers:
As you have correctly stated, pip
installing on the docker image you are using is an older one not supporting --no-cache-dir
. You can try updating that or you can also fix the second problem which is about missing python source headers. This can be fixed by installing python-dev
package. Just add that to the list of packages installed in the Dockerfile:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python
python-dev
python-pip
python-setuptools
groff
less
&& pip install --upgrade awscli
&& apt-get clean
CMD ["/bin/bash"]
You can then run aws
which should be on your path.
Your image is based on Debian Jessie, so you are installing Python 2.7. Try using Python 3.x:
apt-get install -y python3-pip
pip3 install awscli
Adding python-dev
as per this other answer works, but throws an alarming number of compiler warnings (errors?), so I went with a variation of @SergeyKoralev’s answer, which needed some tweaking before it worked.
Here’s the changes I needed to make this work:
- Change to
python3
and pip3
everywhere.
- Add a statement to upgrade
pip
itself.
- Separate the
awscli
install in a separate RUN
command.
Here’s a full repro that does seem to work:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python3
python3-pip
python3-setuptools
groff
less
&& pip3 install --upgrade pip
&& apt-get clean
RUN pip3 --no-cache-dir install --upgrade awscli
CMD ["/bin/bash"]
You can probably also keep the aws
install in the same RUN
layer if you add a shell command before the install that refreshes things after upgrading pip. Not sure how though.
All the answers are about aws-cli version 1, If you want version 2 try the below
FROM node:lts-stretch-slim
RUN apt-get update &&
apt-get install -y
unzip
curl
&& apt-get clean
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
&& unzip awscliv2.zip
&& ./aws/install
&& rm -rf
awscliv2.zip
&& apt-get -y purge curl
&& apt-get -y purge unzip
CMD ["/bin/bash"]
Install AWS CLI in docker container using below command:
apt upgrade -y;apt update;apt install python3 python3-pip python3-setuptools -y; python3 -m pip --no-cache-dir install --upgrade awscli
To check the assumed role or AWS identity run below command:
aws sts get-caller-identity
Using FROM node:18-alpine
; Update your packages then install the required packages before building you dependencies with:
RUN apk --no-cache add --virtual builds-deps build-base python3
I then upgraded pip before installing the AWS CLI
RUN pip install --upgrade pip && pip install --upgrade awscli
.
Here is the fullcode:
## Install required packages for awsebcli ##
RUN apk update && apk add --update --no-cache
git
bash
curl
openssh
python3
py3-pip
py-cryptography
wget
curl
RUN apk --no-cache add --virtual builds-deps build-base python3
RUN pip install --upgrade pip &&
pip install --upgrade awscli
Credit goes to metacollective9
I’m trying to install awscli
using pip
(as per Amazon’s recommendations) in a custom Docker image that comes FROM library/node:6.11.2
. Here’s a repro:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python
python-pip
python-setuptools
groff
less
&& pip --no-cache-dir install --upgrade awscli
&& apt-get clean
CMD ["/bin/bash"]
However, with the above I’m met with:
no such option: --no-cache-dir
Presumably because I’ve got incorrect versions of Python and/or Pip?
I’m installing Python, Pip, and awscli in a similar way with FROM maven:3.5.0-jdk-8
and there it works just fine. I’m unsure what the relevant differences between the two images are.
Removing said option from my Dockerfile doesn’t do me much good either, because then I’m met with a big pile of different errors, an excerpt here:
Installing collected packages: awscli, PyYAML, docutils, rsa, colorama, botocore, s3transfer, pyasn1, jmespath, python-dateutil, futures, six
Running setup.py install for PyYAML
checking if libyaml is compilable
### ABBREVIATED ###
ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
### ABBREVIATED ###
Bottom line: how do you properly install awscli
in library/node:6.x
based images?
As you have correctly stated, pip
installing on the docker image you are using is an older one not supporting --no-cache-dir
. You can try updating that or you can also fix the second problem which is about missing python source headers. This can be fixed by installing python-dev
package. Just add that to the list of packages installed in the Dockerfile:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python
python-dev
python-pip
python-setuptools
groff
less
&& pip install --upgrade awscli
&& apt-get clean
CMD ["/bin/bash"]
You can then run aws
which should be on your path.
Your image is based on Debian Jessie, so you are installing Python 2.7. Try using Python 3.x:
apt-get install -y python3-pip
pip3 install awscli
Adding python-dev
as per this other answer works, but throws an alarming number of compiler warnings (errors?), so I went with a variation of @SergeyKoralev’s answer, which needed some tweaking before it worked.
Here’s the changes I needed to make this work:
- Change to
python3
andpip3
everywhere. - Add a statement to upgrade
pip
itself. - Separate the
awscli
install in a separateRUN
command.
Here’s a full repro that does seem to work:
FROM library/node:6.11.2
RUN apt-get update &&
apt-get install -y
python3
python3-pip
python3-setuptools
groff
less
&& pip3 install --upgrade pip
&& apt-get clean
RUN pip3 --no-cache-dir install --upgrade awscli
CMD ["/bin/bash"]
You can probably also keep the aws
install in the same RUN
layer if you add a shell command before the install that refreshes things after upgrading pip. Not sure how though.
All the answers are about aws-cli version 1, If you want version 2 try the below
FROM node:lts-stretch-slim
RUN apt-get update &&
apt-get install -y
unzip
curl
&& apt-get clean
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
&& unzip awscliv2.zip
&& ./aws/install
&& rm -rf
awscliv2.zip
&& apt-get -y purge curl
&& apt-get -y purge unzip
CMD ["/bin/bash"]
Install AWS CLI in docker container using below command:
apt upgrade -y;apt update;apt install python3 python3-pip python3-setuptools -y; python3 -m pip --no-cache-dir install --upgrade awscli
To check the assumed role or AWS identity run below command:
aws sts get-caller-identity
Using FROM node:18-alpine
; Update your packages then install the required packages before building you dependencies with:
RUN apk --no-cache add --virtual builds-deps build-base python3
I then upgraded pip before installing the AWS CLI
RUN pip install --upgrade pip && pip install --upgrade awscli
.
Here is the fullcode:
## Install required packages for awsebcli ##
RUN apk update && apk add --update --no-cache
git
bash
curl
openssh
python3
py3-pip
py-cryptography
wget
curl
RUN apk --no-cache add --virtual builds-deps build-base python3
RUN pip install --upgrade pip &&
pip install --upgrade awscli
Credit goes to metacollective9