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 · 41 comments
Closed

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

firstval opened this issue Feb 18, 2020 · 41 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 aws-cli@1.x

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

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