Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cli-v2 issue with alpine using Docker #4971

Closed
firstval opened this issue Feb 18, 2020 · 44 comments
Closed

aws-cli-v2 issue with alpine using Docker #4971

firstval opened this issue Feb 18, 2020 · 44 comments

Comments

@firstval
Copy link

firstval commented Feb 18, 2020

I tried to install aws cli v2 with alpine using docker but after installation it doesn't find the aws command even the directories existing. I tried using the following commands

/ # apk add --no-cache curl
/ # curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
/ # unzip awscliv2.zip
/ # ./aws/install
./aws/install: line 78: /aws/dist/aws: not found
You can now run: /usr/local/bin/aws --version

/ # /usr/local/bin/aws --version
sh: /usr/local/bin/aws: not found

/ # aws --version
sh: aws: not found

/ # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

/ # ls /usr/local/bin
aws            aws_completer
@ghost
Copy link

ghost commented Feb 18, 2020

I've been running into this as well - I copy in the bundle, unzip all the files, and I can see that /aws/dist/aws exists. I can ls the directory and stat the file and it's right there, but calling /aws/dist/aws --version fails, saying the file cannot be found, both in the install script and as its own command.

In addition, this also seems to point to a bug where the installer can fail to actually install, but report success anyway, which is a problem.

EDIT:
You can reproduce the issue using this Dockerfile:

FROM docker:stable

RUN apk add curl

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

RUN unzip awscliv2.zip

RUN ./aws/install -i /usr/local/aws -b /usr/local/bin/aws

RUN aws --version && docker -v

I'm seeing output like:

Step 5/6 : RUN ./aws/install -i /usr/local/aws -b /usr/local/bin/aws
 ---> Running in f60e4ff7f68e
./aws/install: line 78: /aws/dist/aws: not found
You can now run: /usr/local/bin/aws/aws --version
Removing intermediate container f60e4ff7f68e
 ---> 3a711e9989ae
Step 6/6 : RUN aws --version && docker -v
 ---> Running in 5015c32e62fe
/bin/sh: aws: Permission denied
The command '/bin/sh -c aws --version && docker -v' returned a non-zero code: 127

Which exhibits the strange behavior where the installation seems to fail on line 78 of the installer, but the install script still seems to succeed, only then to have it fail when we try to actually run the installed bin.

@firstval
Copy link
Author

FYI Found same issues here:
#4685 (comment)

@nateprewitt
Copy link
Member

Hi @firstval, it looks like you found a response on this behavior in #4685. We're currently tracking Docker support in #3553 which would be a prerequisite for this to work.

That said, we can definitely do better with the exceptions being returned. We're working on getting a warning in our install script to will alert you when the platform isn't supported.

We'll track the remaining piece for alpine support in #3553. Thanks!

@Jean-Baptiste-Lasselle
Copy link

stat

Just to add my feddback, I have the exact same error about the aws file not existing, but it actually does, as ls confirmed.

@1giba
Copy link

1giba commented Mar 31, 2020

I've got the same error:

/bin/sh: aws: not found

@rquadling
Copy link

A comment that may not be relevant, but as Alpine uses a different runtime, musl, rather than glibc, could this be the issue? Essentially the binary file presented in the awscli v2 zip file is simply not compatible with Alpine?

@Noirbot
Copy link

Noirbot commented May 5, 2020

@rquadling That is exactly correct. They're looking to see if they can adapt to that, or at least make the errors more helpful, but that's the issue.

@reiz
Copy link

reiz commented May 5, 2020

I have the same issue. Would like to use the aws client to upload minified assets to S3 during build time. But using aws on Alpin is currently a pain in the ass. Version 1.X of aws doesn't support recursive uploads and version 2.0 of aws doesn't run correctly on Alpine. Would be nice if this would be fixed.

@rquadling
Copy link

I don't have a solution for Alpine, but I have got AWSCLI v2, Terraform, and JQ all off of Amazon Linux.

# Based upon https://github.com/aws/aws-cli/blob/2.0.10/docker/Dockerfile
FROM amazonlinux:2 as installer
ARG TERRAFORM_VERSION
RUN yum update -y \
  && yum install -y unzip \
  && curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscli-exe-linux-x86_64.zip \
  && unzip awscli-exe-linux-x86_64.zip \
  # The --bin-dir is specified so that we can copy the
  # entire bin directory from the installer stage into
  # into /usr/local/bin of the final stage without
  # accidentally copying over any other executables that
  # may be present in /usr/local/bin of the installer stage.
  && ./aws/install --bin-dir /aws-cli-bin/ \
  && curl "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip \
  && unzip terraform.zip

FROM amazonlinux:2
COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=installer /aws-cli-bin/ /usr/local/bin/
COPY --from=installer terraform /usr/bin/
RUN yum update -y \
  && yum install -y less groff jq \
  && yum clean all

ENTRYPOINT ["/bin/sh"]

@slashr
Copy link

slashr commented Jun 8, 2020

Why was this closed? Installation of awscli-v2 on Alpine is still failing.

@Noirbot
Copy link

Noirbot commented Jun 8, 2020

My understanding is that it was closed because Alpine isn't officially supported. There's some links to other issues further up in the thread about potentially adding it, or at least adding some sort of workaround.

@rquadling
Copy link

Just come across this : https://hub.docker.com/r/atlassian/pipelines-awscli
Does this work for v2?

@fpalluel
Copy link

Just come across this : https://hub.docker.com/r/atlassian/pipelines-awscli
Does this work for v2?

Hello, I doubt it can work with CLI version 2. You have to use this kind of image, Alpine with glibc.
Or use the custom Dockerfile described in this issue

@marcelloromani
Copy link

I took a different route and installed the aws cli via pip
reference: https://stackoverflow.com/questions/61918972/how-to-install-aws-cli-on-alpine

@AnthonyWC
Copy link

Use https://git.adelielinux.org/adelie/gcompat

apk add gcompat

source: https://wiki.alpinelinux.org/wiki/Running_glibc_programs

@ngtlin
Copy link

ngtlin commented Sep 26, 2021

@AnthonyWC It doesn't work.
Error relocating /usr/local/bin/aws: __strcat_chk: symbol not found
Error relocating /usr/local/bin/aws: __snprintf_chk: symbol not found
Error relocating /usr/local/bin/aws: __vfprintf_chk: symbol not found
Error relocating /usr/local/bin/aws: __realpath_chk: symbol not found
Error relocating /usr/local/bin/aws: __memcpy_chk: symbol not found
Error relocating /usr/local/bin/aws: __vsnprintf_chk: symbol not found
Error relocating /usr/local/bin/aws: __strcpy_chk: symbol not found
Error relocating /usr/local/bin/aws: __fprintf_chk: symbol not found

@marcelloromani
Copy link

(Care to elaborate as to why installing via pip is considered so bad?)

@drewlustro
Copy link

@marcelloromani - the lone, working pip solution in that StackOverflow thread you linked produces [email protected]

People in this thread are interested in 2.x. I'm not sure they have a problem with pip itself.

@kdaily
Copy link
Member

kdaily commented Sep 28, 2021

Hi all,

Please review the recently proposed source distribution for the AWS CLI v2 that has shown success (via third party) for building on Alpine Linux:

#6352 (comment)

There is also an example in the proposal for building on an Alpine Linux container image:

https://github.com/kyleknap/aws-cli/blob/source-proposal/proposals/source-install.md#alpine-linux

@marcelloromani
Copy link

Damn, thanks @drewlustro I must have looked at this in haste.

@smrithinns
Copy link

This worked for me :

apk update
apk add --update py-pip
python -m pip install awscli

@antonmos
Copy link

antonmos commented Nov 3, 2022

This worked for me :

apk update
apk add --update py-pip
python -m pip install awscli

this install aws cli v1 for me.

@Hobart2967
Copy link

Still up to date, the issue is from 2 years ago. Any intention to fix this?

@zeroc0d3
Copy link

This container works for me (using alpine:3.16)


For other container I just add:

# =================== #
#  Install AWSCli v2  #
# =================== #
COPY --from=devopscorner/aws-cli:latest /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=devopscorner/aws-cli:latest /usr/local/bin/ /usr/local/bin/

@msachikanta
Copy link

msachikanta commented Jan 27, 2023

I also had similar issue, when I gone through the AWS documentation, found I have to install following packages as a prerequisite:

glibc, groff, and less

groff and less both are available in Alpine Linux repo, but couldn't find glibc package. However I used musl and gcompat as an alternative (suggested here) which has fixed the issue. Now I can't see any errors during installation.

RUN ./aws/install -i /usr/local/aws-cli -b /usr/bin
You can now run: /usr/bin/aws --version
RUN aws --version
aws-cli/2.1.18 Python/3.7.3 Linux/4.14.299-223.520.amzn2.x86_64 exe/x86_64.alpine.3 prompt/off

Hope this might help others with awscliv2 installation in Alpine Linux.

@PatrickSauts
Copy link

FROM alpine:edge
#Install Aws Client
RUN echo -e -n "\n@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk add aws-cli-v2@testing --no-cache

@Startouf
Copy link

This container works for me (using alpine:3.16)

@zeroc0d3 have you ran into this issue with alpine3.13+ ? have you fixed it somehow ?

@lestersantos
Copy link

#4685 (comment)

Feb 27, I realized that there is aws documentation for the cli v2 in alpine linux as mentioned in this issue 4685.

@pthieu
Copy link

pthieu commented Jun 11, 2023

COPY --from=devopscorner/aws-cli:latest /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=devopscorner/aws-cli:latest /usr/local/bin/ /usr/local/bin/

Not working for me on alpine:3.17, getting the error:

qemu-x86_64: Could not open '/lib/ld-musl-x86_64.so.1': No such file or directory

I'm on arm64 though so may need to explicitly state which architecture?

@jarbot
Copy link

jarbot commented Jun 26, 2023

For Alpine linux this worked for me

apk add --no-cache aws-cli

@HamidullahMuslih
Copy link

@jarbot

For Alpine linux this worked for me

apk add --no-cache aws-cli

It will install verion 1.X

/usr/src/app # aws --version
aws-cli/1.22.81 Python/3.10.12 Linux/5.4.242-156.349.amzn2.x86_64 botocore/1.21.49

@feeh27
Copy link

feeh27 commented Jul 4, 2023

@HamidullahMuslih

@jarbot

For Alpine linux this worked for me

apk add --no-cache aws-cli

It will install verion 1.X

/usr/src/app # aws --version
aws-cli/1.22.81 Python/3.10.12 Linux/5.4.242-156.349.amzn2.x86_64 botocore/1.21.49

Worked for me.

image

I'm using php:8.26-fpm-alpine image.

@wsalles
Copy link

wsalles commented Jul 11, 2023

It is already possible to install aws-cli v2.13.0 natively on Alpine v3.18.

I will put my comment that I made in another issue explaining: #4685 (comment)

@eins
Copy link

eins commented Jul 17, 2023

It is already possible to install aws-cli v2.13.0 natively on Alpine v3.18.

I will put my comment that I made in another issue explaining: #4685 (comment)

@thanks @wsalles . I just used apk 📦
btw it looks like kubectl is already in alpine edge . I can't wait to add it as a binary 📦 just like aws-cli

@nielsbaltodanomatrix
Copy link

nielsbaltodanomatrix commented Jul 19, 2023

we need improve this Dockerfile but works for me

FROM alpine:3.17
ARG AWSCLI_VERSION=2.11.20

# set timezone America/Lima
ENV TZ=America/Lima
ENV TF_CLI_CONFIG_FILE=/home/terraformrc
ARG TERRAGRUNT_VERSION=latest

SHELL ["/bin/ash", "-o", "pipefail", "-c"]

RUN apk update && apk add --no-cache \
  wget=1.21.4-r0 \
  curl=8.1.2-r0 \
  unzip=6.0-r13 \
  bash=5.2.15-r0 \
  jq=1.6-r2 \
  gettext=0.21.1-r1 \
  python3=3.10.12-r0 \
  py3-pip=22.3.1-r1 \
  #install jq
  jo=1.9-r0 \
  nodejs=18.16.1-r0 \
  # nodejs \
  npm=9.1.2-r0 \
  #install yq 
  yq=4.30.4-r4 \
  && rm -rf /var/cache/apk/*

# Install Docker dependencies
RUN apk add --no-cache \
    docker=20.10.24-r2 \
    openrc=0.45.2-r7 \
    && rc-update add docker boot

#upgrade pip and set timezone
RUN pip install --no-cache-dir \
  boto3==1.26.46 \
  pyYAML==5.4.1 \
  htmlmin==0.1.12 \
  Jinja2==3.1.2 \
  && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
  && curl -s https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip -o /tmp/terraform_1.4.6_linux_amd64.zip && \
  unzip /tmp/terraform_1.4.6_linux_amd64.zip -d /tmp/ && \
  chmod +x /tmp/terraform && mv /tmp/terraform /usr/bin/ && \
  rm -rf /tmp/terraform_1.4.6_linux_amd64.zip && \
  TERRAGRUNT_VERSION_INSTALL=$(curl -s https://api.github.com/repos/gruntwork-io/terragrunt/releases/latest | grep tag_name | cut -d '"' -f 4) && \
  curl -LO https://github.com/gruntwork-io/terragrunt/releases/download/"${TERRAGRUNT_VERSION_INSTALL}"/terragrunt_linux_amd64 && \
  chmod +x terragrunt_linux_amd64 && \
  mv terragrunt_linux_amd64 /usr/bin/terragrunt

#install awscli
#depencies for awscli v2
RUN apk add --no-cache \
  git=2.38.5-r0 \
  groff=1.22.4-r2 \
  less=608-r1 \
  mailcap=2.1.54-r0 \
  build-base=0.5-r3 \
  libffi-dev=3.4.4-r0 \
  cmake=3.24.4-r0 \
  openssl-dev=3.0.9-r1 \
  python3-dev=3.10.12-r0

WORKDIR /tmp

RUN git clone --single-branch --depth 1 -b "${AWSCLI_VERSION}" https://github.com/aws/aws-cli.git && \
  ./aws-cli/configure --with-install-type=portable-exe --with-download-deps && \
  make && \
  make install && \
  rm -rf /tmp/aws-cli \
  && rm -rf \
    /usr/local/lib/aws-cli/aws_completer \
    /usr/local/lib/aws-cli/awscli/data/ac.index \
    /usr/local/lib/aws-cli/awscli/examples \
    && find /usr/local/lib/aws-cli/awscli/data -name "completions-1*.json" -delete && \
    find /usr/local/lib/aws-cli/awscli/botocore/data -name examples-1.json -delete

WORKDIR /usr/local/lib/aws-cli
RUN for a in *.so*; do test -f "/lib/$a" && rm "$a"; done

ENTRYPOINT ["/usr/bin/terraform"]

@TeemuKoivisto
Copy link

Highly annoying that installing aws cli has become so complicated in v2. Not only this issue with Alpine but also the need to choose between right CPU architecture when you download the zip.

I made this Gist incase it helps someone else https://gist.github.com/TeemuKoivisto/a99d51a2e4d86ebefad353ab2d4273ae

@stevekm
Copy link

stevekm commented Oct 18, 2023

@nielsbaltodanomatrix with a Dockerfile like that I cant help but wonder what the benefit is of using Alpine. I just did a test build and it seems like that container comes in around 1.4GB in size. At that point I would just use Ubuntu as the base image instead, and you would avoid the issue of compatibility with aws as well

@marcelloromani
Copy link

marcelloromani commented Oct 29, 2023

Hopefully it's old news by now but it's finally dead easy to install aws cli v2 on alpine.

FROM alpine:3.18.4
RUN apk add --no-cache aws-cli
$ docker build -t aws-cli-v2-alpine .
$ docker image ls
REPOSITORY                        TAG                    IMAGE ID       CREATED              SIZE
aws-cli-v2-alpine                 latest                 d575d170a8f1   12 seconds ago       170MB
$ docker run --rm -it aws-cli-v2-alpine aws --version
aws-cli/2.13.5 Python/3.11.6 Linux/5.10.124-linuxkit source/aarch64.alpine.3 prompt/off

Tested on Mac OS 14.0
Docker Desktop 4.12.0

@eins
Copy link

eins commented Oct 30, 2023

Hopefully it's old news by now but it's finally dead easy to install aws cli v2 on alpine.

FROM alpine:3.18.4
RUN apk add --no-cache aws-cli
$ docker build -t aws-cli-v2-alpine .
$ docker image ls
REPOSITORY                        TAG                    IMAGE ID       CREATED              SIZE
aws-cli-v2-alpine                 latest                 d575d170a8f1   12 seconds ago       170MB
$ docker run --rm -it aws-cli-v2-alpine aws --version
aws-cli/2.13.5 Python/3.11.6 Linux/5.10.124-linuxkit source/aarch64.alpine.3 prompt/off

Tested on Mac OS 14.0 Docker Desktop 4.12.0

@marcelloromani this is really great. awscli is in 3.18 branch . I can't wait for kubectl to move to the next stable branch. the image is really tiny and it works in arm64

@SaranshIam
Copy link

For Anyone still facing this issue, use
apk add --no-cache aws-cli
to install aws-cli

@Matthieulvt
Copy link

The error is still present for the image alpine:edge on architecture x86_64:

Command runned : apk add --no-cache aws-cli

Docker Image : alpine:edge

-> Package is not present for the architecture x86_64 : https://pkgs.alpinelinux.org/packages?name=aws-cli&branch=edge&repo=&arch=x86_64&maintainer=None (only for Arch)

image

@gnought
Copy link

gnought commented May 23, 2024

At this moment of writing, aws-cli is only available natively in Alpine 3.19, not 3.20 and edge
https://pkgs.alpinelinux.org/packages?name=aws-cli&branch=v3.19&repo=&arch=&maintainer=

@mztnnrt
Copy link

mztnnrt commented May 23, 2024

Thanks @gnought 🙏

currently build our Dockerfile is failure, so i arrived this issue.
our workaround is below, based on this comment #4971 (comment)

- FROM alpine:latest
+ FROM alpine:3.19
RUN apk add --no-cache aws-cli
CMD ["/bin/sh"]

※ but we don't understand why now it's impossible to add use alpine:latest

@gnought
Copy link

gnought commented Jun 13, 2024

I guess the page is a bit outdated. Today I found that aws-cli v2 is now available in alpine:3.20

gnought:~ √ % docker run --rm -it --pull always alpine:3.20 sh
3.20: Pulling from library/alpine
Digest: sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd
Status: Image is up to date for alpine:3.20
/ # apk add aws-cli
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/aarch64/APKINDEX.tar.gz
(1/62) Installing libbz2 (1.0.8-r6)
(2/62) Installing libexpat (2.6.2-r0)
(3/62) Installing libffi (3.4.6-r0)
(4/62) Installing gdbm (1.23-r1)
(5/62) Installing xz-libs (5.6.1-r3)
(6/62) Installing libgcc (13.2.1_git20240309-r0)
(7/62) Installing libstdc++ (13.2.1_git20240309-r0)
(8/62) Installing mpdecimal (4.0.0-r0)
(9/62) Installing ncurses-terminfo-base (6.4_p20240420-r0)
(10/62) Installing libncursesw (6.4_p20240420-r0)
(11/62) Installing libpanelw (6.4_p20240420-r0)
(12/62) Installing readline (8.2.10-r0)
(13/62) Installing sqlite-libs (3.45.3-r1)
(14/62) Installing python3 (3.12.3-r1)
(15/62) Installing python3-pycache-pyc0 (3.12.3-r1)
(16/62) Installing pyc (3.12.3-r1)
(17/62) Installing py3-certifi (2024.2.2-r1)
(18/62) Installing py3-certifi-pyc (2024.2.2-r1)
(19/62) Installing py3-cparser (2.22-r1)
(20/62) Installing py3-cparser-pyc (2.22-r1)
(21/62) Installing py3-cffi (1.16.0-r1)
(22/62) Installing py3-cffi-pyc (1.16.0-r1)
(23/62) Installing py3-cryptography (42.0.7-r0)
(24/62) Installing py3-cryptography-pyc (42.0.7-r0)
(25/62) Installing py3-six (1.16.0-r9)
(26/62) Installing py3-six-pyc (1.16.0-r9)
(27/62) Installing py3-dateutil (2.9.0-r1)
(28/62) Installing py3-dateutil-pyc (2.9.0-r1)
(29/62) Installing py3-distro (1.9.0-r2)
(30/62) Installing py3-distro-pyc (1.9.0-r2)
(31/62) Installing py3-colorama (0.4.6-r5)
(32/62) Installing py3-colorama-pyc (0.4.6-r5)
(33/62) Installing py3-docutils (0.20.1-r2)
(34/62) Installing py3-docutils-pyc (0.20.1-r2)
(35/62) Installing py3-jmespath (1.0.1-r3)
(36/62) Installing py3-jmespath-pyc (1.0.1-r3)
(37/62) Installing py3-urllib3 (1.26.18-r1)
(38/62) Installing py3-urllib3-pyc (1.26.18-r1)
(39/62) Installing py3-wcwidth (0.2.13-r1)
(40/62) Installing py3-wcwidth-pyc (0.2.13-r1)
(41/62) Installing py3-prompt_toolkit (3.0.43-r1)
(42/62) Installing py3-prompt_toolkit-pyc (3.0.43-r1)
(43/62) Installing py3-ruamel.yaml.clib (0.2.8-r1)
(44/62) Installing py3-ruamel.yaml (0.17.28-r1)
(45/62) Installing py3-ruamel.yaml-pyc (0.17.28-r1)
(46/62) Installing aws-cli-pyc (2.15.57-r0)
(47/62) Installing py3-awscrt-pyc (0.20.3-r1)
(48/62) Installing python3-pyc (3.12.3-r1)
(49/62) Installing aws-c-common (0.9.19-r0)
(50/62) Installing aws-c-cal (0.6.14-r0)
(51/62) Installing aws-c-compression (0.2.18-r0)
(52/62) Installing s2n-tls (1.4.14-r0)
(53/62) Installing aws-c-io (0.14.8-r0)
(54/62) Installing aws-c-http (0.8.1-r0)
(55/62) Installing aws-c-sdkutils (0.1.16-r0)
(56/62) Installing aws-c-auth (0.7.22-r0)
(57/62) Installing aws-checksums (0.1.17-r1)
(58/62) Installing aws-c-event-stream (0.4.2-r0)
(59/62) Installing aws-c-mqtt (0.10.4-r0)
(60/62) Installing aws-c-s3 (0.5.9-r0)
(61/62) Installing py3-awscrt (0.20.3-r1)
(62/62) Installing aws-cli (2.15.57-r0)
Executing busybox-1.36.1-r28.trigger
OK: 189 MiB in 76 packages
/ # aws --version
aws-cli/2.15.57 Python/3.12.3 Linux/6.9.3-orbstack-00146-g1a8d02c90788 source/aarch64.alpine.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests