dash on alpine linux (in docker) - docker

I'm trying to install dash in the (dockerized) alpine linux.
My Dockerfile follows:
FROM alpine:latest
RUN \
echo "#community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk add --no-cache --update dash
ENV SHELL dash
CMD dash
the output I get:
Step 1/4 : FROM alpine:latest
---> 053cde6e8953
Step 2/4 : RUN echo "#community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && apk add --no-cache --update dash
---> Running in 680f3d4d7dda
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
dash-0.5.9.1-r0:
masked in: #community
satisfies: world[dash]
ERROR: Service 'dash_alpine' failed to build: The command '/bin/sh -c echo "#community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && apk add --no-cache --update dash' returned a non-zero code: 1
however based on the alpine linux package search it seems to be available in the community repo: https://pkgs.alpinelinux.org/packages?name=dash&branch=edge&repo=&arch=&maintainer=
What should I change to make it working?

I think your echo line is wrong.
This file works well for me.
FROM alpine:edge
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk add -U --no-cache dash

Related

Docker: Error code 127 when executing shell script

So I can't seem to figure this out, but I'm getting error code 127 when running a Dockerfile. What causes this error?
My Dockerfile:
FROM composer as comp
FROM php:7.4-fpm-alpine
COPY --from=comp /usr/bin/composer /usr/bin/composer
COPY ./docker/install-deps.sh /tmp/install-deps.sh
RUN echo $(ls /tmp)
RUN /tmp/install-deps.sh
COPY . /var/www
WORKDIR /var/www
RUN composer install -o --no-dev
The results after building the Dockerfile:
Building php
Step 1/9 : FROM composer as comp
---> 433420023b60
Step 2/9 : FROM php:7.4-fpm-alpine
---> 78e945602ecc
Step 3/9 : COPY --from=comp /usr/bin/composer /usr/bin/composer
---> 46117e22b4de
Step 4/9 : COPY ./docker/install-deps.sh /tmp/install-deps.sh
---> 7e46a2ee759c
Step 5/9 : RUN echo $(ls /tmp)
---> Running in aa1f900032f9
install-deps.sh
Removing intermediate container aa1f900032f9
---> eb455e78b7f6
Step 6/9 : RUN /tmp/install-deps.sh
---> Running in 6402a15cccb2
/bin/sh: /tmp/install-deps.sh: not found
ERROR: Service 'php' failed to build: The command '/bin/sh -c /tmp/install-deps.sh' returned a non-zero code: 127
The install-deps.sh:
#!/bin/sh
set -e
apk add --update --no-cache \
postgresql-dev \
mysql-client \
yaml-dev \
git \
openssl
docker-php-ext-install pcntl pdo_mysql pdo_pgsql
# yaml
apk add --no-cache --virtual .build-deps g++ make autoconf
pecl channel-update pecl.php.net
pecl install yaml
docker-php-ext-enable yaml
apk del --purge .build-deps
Docker is executing the install-deps.sh script. The issue is with a command inside install-deps.sh that is not recognized when docker attempts to run the script.
As you can see the script returns an error code of 127 meaning that a command within the file does not exist.
For instance - try this:
touch test.sh
echo "not-a-command" >> test.sh
chmod 755 test.sh
/bin/sh -c "./test.sh"
Output:
/root/test.sh: line 1: not-a-command: command not found
Now check the exit code:
echo $?
127
I would suggest running the script inside an interactive environment to identify/install the command that is not found.

Docker alpine:edge how to enable testing

EDIT: now Alpine may provide a bazel package...
ref: https://pkgs.alpinelinux.org/packages?name=bazel*&
I want to install bazel from testing repository in my Dockerfile.
FROM alpine:edge AS env
RUN apk add --no-cache git build-base bazel
CMD [ "/bin/sh" ]
observed:
$ docker build --target env -t test .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM alpine:edge AS env
---> 24cae4d038c0
Step 2/3 : RUN apk add --no-cache git build-base bazel
---> Running in 6ce08db21af0
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
bazel (missing):
required by: world[bazel]
The command '/bin/sh -c apk add --no-cache git build-base bazel' returned a non-zero code: 1
Simply use:
# Create a virtual environment with all tools installed
# ref: https://hub.docker.com/_/alpine
FROM alpine:edge AS env
RUN apk add --no-cache git build-base
RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing bazel
CMD [ "/bin/sh" ]

GitLab pipeline Docker build gets stuck on apk

Trying to make a simple GitLab pipeline that builds a Docker image for Alpine Linux + Openshift CLI.
This is the code:
FROM frolvlad/alpine-glibc:latest
MAINTAINER Daniel Widerin <daniel#widerin.net>
ENV OC_VERSION=v3.11.0 \
OC_TAG_SHA=0cbc58b \
BUILD_DEPS='tar gzip' \
RUN_DEPS='curl ca-certificates gettext'
RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS && \
curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && \
tar xzvf /tmp/oc.tar.gz -C /tmp/ && \
mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && \
rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit && \
apk del $BUILD_DEPS
CMD ["/bin/sh"]
Now for some reason when running the pipeline it gets stuck on the curl part that downloads the openshift archive.
Status: Downloaded newer image for frolvlad/alpine-glibc:latest
---> 38dd85a430e8
Step 2/5 : MAINTAINER Daniel Widerin <daniel#widerin.net>
---> Running in bdacc7e92e79
Removing intermediate container bdacc7e92e79
---> c56da0a68f7f
Step 3/5 : ENV OC_VERSION=v3.11.0 OC_TAG_SHA=0cbc58b BUILD_DEPS='tar gzip' RUN_DEPS='curl ca-certificates gettext'
---> Running in cb1e6cdb39ca
Removing intermediate container cb1e6cdb39ca
---> 727952120e67
Step 4/5 : RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS && curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && tar xzvf /tmp/oc.tar.gz -C /tmp/ && mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit && apk del $BUILD_DEPS
---> Running in ef344ef4a96b
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
It stays like this for an hour until the pipeline times out.
Tried this same Dockerfile manually and it works fine.
How can I diagnose this issue? How can I find any logs for this?
Found that this issue is related to Alpine image having networking issues when run in Docker-in-Docker configuration on Kubernetes/OpenShift based runner. Adding --network host to Docker build helps to fix this issue.
Docker build --network host .
Related GitHub issue: github.com/gliderlabs/docker-alpine/issues/307

Docker build failed: "unsatisfable contraints"

I've written this straightforward Dockerfile:
FROM alpine
WORKDIR /usr/src
RUN apk add --no-cache curl jq
RUN mkdir /env
COPY src/* /usr/src/
RUN chmod u+x /usr/src/*.sh
CMD /usr/src/wsec.sh
When I try to build the image, I'm getting this error message:
Sending build context to Docker daemon 43.52kB
Step 1 : FROM alpine
---> 3fd9065eaf02
Step 2 : WORKDIR /usr/src
---> Using cache
---> 4c7b79dc4239
Step 3 : RUN apk add --no-cache curl jq
---> Running in 0cf83217477a
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz: temporary error (try again later)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz: temporary error (try again later)
ERROR: unsatisfiable constraints:
curl (missing):
required by: world[curl]
jq (missing):
required by: world[jq]
The command '/bin/sh -c apk add --no-cache curl jq' returned a non-zero code: 2
It could happen that main alpine repository http://dl-cdn.alpinelinux.org/alpine is temporary unavailable. Just like in your case. In order to be not blocked on this issue, we should add other alpine repositories to our alpine image:
http://dl-2.alpinelinux.org
http://dl-3.alpinelinux.org
http://dl-4.alpinelinux.org
http://dl-5.alpinelinux.org
So, the final Dockerfile is:
FROM alpine
WORKDIR /usr/src
RUN echo "http://dl-2.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories && \
echo "http://dl-2.alpinelinux.org/alpine/v3.7/community" >> /etc/apk/repositories && \
echo "http://dl-3.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories && \
echo "http://dl-3.alpinelinux.org/alpine/v3.7/community" >> /etc/apk/repositories && \
echo "http://dl-4.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories && \
echo "http://dl-4.alpinelinux.org/alpine/v3.7/community" >> /etc/apk/repositories && \
echo "http://dl-5.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories && \
echo "http://dl-5.alpinelinux.org/alpine/v3.7/community" >> /etc/apk/repositories
RUN apk add --no-cache curl jq
RUN mkdir /env
COPY src/* /usr/src/
RUN chmod u+x /usr/src/*.sh
CMD /usr/src/wsec.sh

Why is bin/sh not found on my alpine based docker-compose build?

I am building a docker stack based on alpine. Given my:
php7-dockerfile:
FROM php:7-fpm-alpine
RUN apk update && \\
apk upgrade && \\
apk add --update autoconf gcc
and docker-compose.yml:
version: "2"
services:
php:
build:
context: .
dockerfile: php7-dockerfile
container_name: test_php
volumes_from:
- data
On running docker-compose build I am getting:
Building data
Step 1 : FROM busybox
---> 47bcc53f74dc
Step 2 : ADD ./web /var/www/html
---> Using cache
---> fc7f0c26a44d
Successfully built fc7f0c26a44d
Building php
Step 1 : FROM php:7-fpm-alpine
---> 86c28f7ac7f5
Step 2 : RUN apk update && \ apk upgrade && \ apk add --update autoconf gcc
---> Running in dc5c837f869c
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.1-13-gdf6ff3e [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.0-75-g8d1dc52 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5966 distinct packages available
/bin/sh: : not found
ERROR: Service 'php' failed to build: The command '/bin/sh -c apk update && \ apk upgrade && \ apk add --update autoconf gcc' returned a non-zero code: 127
I am confused as to why it uses /bin/sh and why it is not found, as in my existing running container I can run
$ docker exec -it test_php /bin/sh
/var/www/html #
What am I doing wrong?
In order to use a newline on a combined RUN command, don't use \\ but \.
RUN apk update && \
apk upgrade && \
apk add --update autoconf gcc
The error message is misleading in this case.

Resources