alpine linux apk installation error in Dockerfile - linux

I am trying to execute the following code in a Dockerfile:
FROM alpine:3.7
RUN apk update && apk add --no-cache busybox musl prometheus-node-exporter
RUN rc-update add prometheus-node-exporter default
RUN rc-service prometheus-node-exporter start
RUN echo " - job_name: node \
# If prometheus-node-exporter is installed, grab stats about the local \
# machine by default. \
static_configs: \
- targets: ['localhost:9100', 'alpine_distro:9100']" >> /etc/prometheus/prometheus.yml
but my build returns the following error:
ERROR:
unsatisfiable constraints:
prometheus-node-exporter (missing):
required by: world[prometheus-node-exporter]
The command '/bin/sh -c apk update && apk add --no-cache busybox musl prometheus-node-exporter' returned a non-zero code: 1
I am not used to Alpine package manager but my guess is that I might not be using a repo that contains prometheus-node-exporter?
Or am I missing something else?

If from some reason you're forced to use Alpine 3.7, you could install the prometheus-node-exporter package from the Alpine 3.13 community repo:
$ sudo docker run -it alpine:3.7
/ # apk add prometheus-node-exporter --repository=http://dl-cdn.alpinelinux.org/alpine/v3.13/community
fetch http://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/1) Installing prometheus-node-exporter (1.0.1-r0)
Executing prometheus-node-exporter-1.0.1-r0.pre-install
24% ###################################
Executing busybox-1.27.2-r11.trigger
OK: 20 MiB in 14 packages
/ #
/ #
/ # node_exporter --help
usage: node_exporter [<flags>]
...
It seems node_exporter only depends on musl, so it's likely to work well without special issues:
/ # ldd /usr/bin/node_exporter
/lib/ld-musl-x86_64.so.1 (0x7fea4c68a000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fea4c68a000)
However, if you have that option, it's recommended to upgrade your base Alpine version to 3.13, instead.

Related

Alpine 3.11 diff: unrecognized option: c BusyBox v1.31.1 () multi-call binary

I am using an alpine 3.11 to build my image, everything goes well during the build the dockefile is here below :
FROM alpine:3.11
LABEL version="1.0"
ARG UID="110"
ARG PYTHON_VERSION="3.8.10-r0"
ARG ANSIBLE_VERSION="5.0.1"
ARG AWSCLI_VERSION="1.22.56"
# Create jenkins user with sudo privileges
RUN adduser -u ${UID} -D -h /home/jenkins/ jenkins
RUN echo 'jenkins ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN mkdir -p /tmp/.ansible
RUN chown -R jenkins:jenkins /tmp/.ansible
# Install minimal packages
RUN apk --update --no-cache add bash bind-tools curl gcc git libffi-dev libpq make mysql-client openssl postgresql-client sudo unzip wget coreutils
#RUN apk --update --no-cache add py-mysqldb
RUN apk --update --no-cache add python3=${PYTHON_VERSION} python3-dev py3-pip py3-cryptography
# Install JQ from sources
RUN wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
RUN mv jq-linux64 /usr/bin/jq
RUN chmod +x /usr/bin/jq
# Install ansible and awscli with python package manager
RUN pip3 install --upgrade pip
RUN pip3 install yq --ignore-installed PyYAML
RUN pip3 install ansible==${ANSIBLE_VERSION}
RUN pip3 install awscli==${AWSCLI_VERSION} boto boto3 botocore s3cmd pywinrm pymysql 'python-dateutil<2.8.1'
# Clean cache
RUN rm -rf /var/cache/apk/*
# Display packages versions
RUN python3 --version && \
pip3 --version && \
ansible --version && \
aws --version
this image is later used to lunch some jenkins jobs nothing unusual.
But when i try to use the diff command in of these jobs I have the following error :
diff: unrecognized option: c BusyBox v1.31.1 () multi-call binary
that's why i tried to install the coreutils package but still the "-c" option is still unrecognized which is weird.
So my question is there a way to add the -c option for the diff command because in the manual of GNU this should be available automatically but apparently not on Alpine ? if there is a way could anyone please share it.
P.S : In case you are wondering why am I using the diff command it is just to compare two json files and the -c is necessary for me in this context.
Well I just had to add the diffutils package to the list after installing it everything works well
In spite of it being required in the POSIX diff specification it looks like the BusyBox implementation of diff doesn't support the -c option.
One thing you could do is change your diff invocation to use unified context diff format. Again, BusyBox diff appears to not support -u, so you need to use an explicit -U option with the number of lines of context
diff -U3 file.orig file.new
In general, the Alpine environment has many small differences like this. If you're installing the GNU versions of these tools anyways – your Dockerfile already installs GNU bash and coreutils – you'll probably find minimal to no space savings from using an Alpine base image, and using a Debian or Ubuntu base that already includes the GNU versions of these tools will be easier.
FROM ubuntu:20.04 # not Alpine
...
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
bind9-utils \
build-essential \
curl \
git-core \
...
You may need to search on https://packages.debian.org/ to find equivalent Debian packages. build-essential is a metapackage that includes the entire C toolchain (gcc, make, et al.); bash, coreutils, and diffutils would typically be installed as part of the base distribution image.

Rootless docker causes "failed to resolve address for github.com"

In my dockerfile i'm installing cryptography python dependency however when building wheel from rootless docker i'm getting following error:
...
generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
running build_rust
Updating crates.io index
warning: spurious network error (2 tries remaining): failed to resolve address for github.com: Name does not resolve; class=Net (12)
warning: spurious network error (1 tries remaining): failed to resolve address for github.com: Name does not resolve; class=Net (12)
error: failed to get `pyo3` as a dependency of package `cryptography-rust v0.1.0 (/tmp/pip-install-h22hlaqn/cryptography_a2037904c10949639ccf8a3b2519f187/src/rust)`
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
network failure seems to have happened
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Caused by:
failed to resolve address for github.com: Name does not resolve; class=Net (12)
=============================DEBUG ASSISTANCE=============================
If you are seeing a compilation error please try the following steps to
successfully install cryptography:
1) Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
2) Read https://cryptography.io/en/latest/installation.html for specific
instructions for your platform.
3) Check our frequently asked questions for more information:
https://cryptography.io/en/latest/faq.html
4) Ensure you have a recent Rust toolchain installed:
https://cryptography.io/en/latest/installation.html#rust
5) If you are experiencing issues with Rust for *this release only* you may
set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
=============================DEBUG ASSISTANCE=============================
...
The strangest thing that the same dockerfile compiles absolutely successfully when built from root user.
I'm using the most recent docker version on arch linux and have tried following instructions here: https://docs.docker.com/engine/security/rootless/ and installing AUR and in both cases had no luck.
That's my docker file:
FROM python:3.7-alpine
ENV LANG C.UTF-8
RUN apk update \
&& apk add --virtual build-deps gcc g++ musl-dev python3 python3-dev autoconf automake linux-headers make libffi-dev openssl-dev \
&& apk add --no-cache bash postgresql-dev libxml2-dev libxslt-dev jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev git openssh-client rust cargo
RUN mkdir -p /opt/carryall/app
RUN mkdir -p /opt/carryall/static
RUN mkdir -p /opt/carryall/media
WORKDIR /opt/carryall/app
RUN mkdir /root/.ssh/
ADD id_rsa /root/.ssh/id_rsa_temp
RUN cat /root/.ssh/id_rsa_temp | tr -d '\r' > /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
ADD requirements.txt /opt/carryall/app/
RUN pip install --no-cache-dir -r /opt/carryall/app/requirements.txt
RUN apk del --purge build-deps \
&& rm -rf /root/.cache /tmp/*
ADD . /opt/carryall/app

Unable to run aliyun-cli in Docker:stable container after installing it. Errors as command not found

I am unsure if stack overflow or system fault is the right stack exchange site but I'm going with stack overflow cause the alicloud site posted to add a tag and ask a question here.
So. I'm currently building an image based on Docker:stable, that is an alpine distro, that will have aliyun-cli installed and available for use. However I am getting a weird error of Command Not Found when I'm running it. I have followed the guide here https://partners-intl.aliyun.com/help/doc-detail/139508.htm and moved the aliyun binary to /usr/sbin
Here is my Dockerfile for example
FROM docker:stable
RUN apk update && apk add curl
#Install python 3
RUN apk update && apk add python3 py3-pip
#Install AWS Cli
RUN pip3 install awscli --upgrade
# Install Aliyun CLI
RUN curl -L -o aliyun-cli.tgz https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.30-amd64.tgz
RUN tar -xzvf aliyun-cli.tgz
RUN mv aliyun /usr/bin
RUN chmod +x /usr/bin/aliyun
RUN rm aliyun-cli.tgz
However when i'm running aliyun (which can be auto-completed) I am getting this
/ # aliyun
sh: aliyun: not found
I've tried moving it to other bins. Cding into the folder and calling it explicitly but still always getting a command not found. Any suggestions would be welcome.
Did you check this Dockerfile?
Also why you need to install aws-cli in the same image and why you will need to maintain it for your self when AWS provide managed aws-cli image.
docker run --rm -it amazon/aws-cli --version
that's it for aws-cli image,but if you want in existing image then you can try
RUN pip install awscli --upgrade
DockerFile
FROM python:2-alpine3.8
LABEL com.frapsoft.maintainer="Maik Ellerbrock" \
com.frapsoft.version="0.1.0"
ARG SERVICE_USER
ENV SERVICE_USER ${SERVICE_USER:-aliyun}
RUN apk add --no-cache curl
RUN curl https://raw.githubusercontent.com/ellerbrock/docker-collection/master/dockerfiles/alpine-aliyuncli/requirements.txt > /tmp/requirements.txt
RUN \
adduser -s /sbin/nologin -u 1000 -H -D ${SERVICE_USER} && \
apk add --no-cache build-base && \
pip install aliyuncli && \
pip install --no-cache-dir -r /tmp/requirements.txt && \
apk del build-base && \
rm -rf /tmp/*
USER ${SERVICE_USER}
WORKDIR /usr/local/bin
ENTRYPOINT [ "aliyuncli" ]
CMD [ "--help" ]
build and run
docker build -t aliyuncli .
docker run -it --rm aliyuncli
output
docker run -it --rm abc aliyuncli
usage: aliyuncli <command> <operation> [options and parameters]
<aliyuncli> the valid command as follows:
batchcompute | bsn
bss | cms
crm | drds
ecs | ess
ft | ocs
oms | ossadmin
ram | rds
risk | slb
ubsms | yundun
After a lot of lookup I found a github issue in the official aliyun-cli that sort of describes that it is not compatible with alpine linux because of it's not muslc compatible.
Link here: https://github.com/aliyun/aliyun-cli/issues/54
Following the workarounds there I build a multi-stage docker file with the following that simply fixed my issue.
Dockerfile
#Build aliyun-cli binary ourselves because of issue
#in alpine https://github.com/aliyun/aliyun-cli/issues/54
FROM golang:1.13-alpine3.11 as cli_builder
RUN apk update && apk add curl git make
RUN mkdir /srv/aliyun
WORKDIR /srv/aliyun
RUN git clone https://github.com/aliyun/aliyun-cli.git
RUN git clone https://github.com/aliyun/aliyun-openapi-meta.git
ENV GOPROXY=https://goproxy.cn
WORKDIR aliyun-cli
RUN make deps; \
make testdeps; \
make build;
FROM docker:19
#Install python 3 & jq
RUN apk update && apk add python3 py3-pip python3-dev jq
#Install AWS Cli
RUN pip3 install awscli --upgrade
# Install Aliyun CLI from builder
COPY --from=cli_builder /srv/aliyun/aliyun-cli/out/aliyun /usr/bin
RUN aliyun configure set --profile default --mode EcsRamRole --ram-role-name build --region cn-shanghai

How to check if libpcap installed in Alphine docker container

I installed libpcap in my container using below docker file using docker file below. How do I make sure it was installed and working as expected?
I tried below with the hope to see libpcap
D:\work >docker exec -u 0 -it containerId sh
/app # cd /etc/apk
/etc/apk # cat repositories
http://dl-cdn.alpinelinux.org/alpine/v3.8/main
http://dl-cdn.alpinelinux.org/alpine/v3.8/community
/etc/apk #
Below is my docker file
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS build
# Install packages
RUN apk update
RUN apk -U --no-cache add libpcap
Running the apk info command has below output
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
musl
busybox
alpine-baselayout
alpine-keys
libressl2.7-libcrypto
libressl2.7-libssl
libressl2.7-libtls
ssl_client
zlib
apk-tools
scanelf
musl-utils
libc-utils
ca-certificates
krb5-conf
libcom_err
keyutils-libs
libverto
krb5-libs
libgcc
libintl
libcrypto1.0
libssl1.0
libstdc++
userspace-rcu
lttng-ust
tzdata
Run docker exec command and try this
$ apk info
This will list all the installed packages in alpine.
I can see libcap in the output.
If you still can't see the package. Make sure you have run apk update before installing libcap

Docker Alpine linux package masked

I am trying to install a package on my docker image that runs alpine but I get the following error,
Removing intermediate container 54bbe0932899
Step 14 : RUN apk add openblas openblas-dev --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
---> Running in 24d7a8c00c89
fetch http://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
openblas-0.2.19-r0:
masked in: #community
satisfies: world[openblas]
openblas-dev-0.2.19-r0[openblas=0.2.19-r0]
openblas-ilp64-0.2.19-r0:
masked in: #community
satisfies:
openblas-dev-0.2.19-r0[openblas-ilp64=0.2.19-r0]
openblas-dev-0.2.19-r0:
masked in: #community
satisfies: world[openblas-dev]
ERROR: Service 'web' failed to build: The command '/bin/sh -c apk add openblas openblas-dev --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted' returned a non-zero code: 3
Important part of the Dockerfile:
FROM python:3.5.2-alpine
ADD repositories /etc/apk/repositories
RUN apk upgrade --update
RUN apk add --update libstdc++ curl ca-certificates bash
RUN apk add openblas openblas-dev --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
RUN apk add --update py-scipy py-numpy py-numpy-dev
The repository file is
http://dl-cdn.alpinelinux.org/alpine/v3.4/main
#testing http://dl-cdn.alpinelinux.org/alpine/edge/testing
#community http://dl-cdn.alpinelinux.org/alpine/edge/community
How I can force the installation of openblas?
I am new to alpine so apologies if this is a straight forward question.
I found the solution,
the following line:
RUN apk add openblas openblas-dev --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
should be
RUN apk add openblas#community openblas-dev#community --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ --allow-untrusted
Now docker continues to the next stage.

Resources