Docker build failed: "unsatisfable contraints" - docker

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

Related

docker suddenly stopped working, executor failed running [/bin/sh -c echo

Hello this is my docker file:
FROM golang:alpine3.15 as builder
RUN apk add ca-certificates git make gcc musl-dev libc6-compat curl chromium bash curl
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories \
&& apk upgrade -U -a \
&& apk add \
libstdc++ \
chromium \
harfbuzz \
nss \
freetype \
ttf-freefont \
font-noto-emoji \
wqy-zenhei
RUN mkdir /build
ADD go.* /build/
WORKDIR /build
RUN go mod download -x
ADD main.go /build/
RUN CGO_ENABLED=0 GOOS=linux go build -a -o /api
FROM alpine:3.15
COPY --from=builder /api .
EXPOSE 8080
ENTRYPOINT [ "/api" ]
STOPSIGNAL SIGKILL
I have been using same image on save ubuntu version, since past 4 months. But now when I run docker-compose up --build I always get this error:
failed to solve: executor failed running [/bin/sh -c echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories && apk upgrade -U -a && apk add libstdc++ chromium harfbuzz nss freetype ttf-freefont font-noto-emoji wqy-zenhei]: exit code: 1
What could be the issue? Thanks
Found these errors too:
#0 3.144 ERROR: ca-certificates-bundle-20220614-r2: trying to overwrite etc/ssl1.1/cert.pem owned by libcrypto1.1-1.1.1q-r0.
#0 3.144 ERROR: ca-certificates-bundle-20220614-r2: trying to overwrite etc/ssl1.1/certs owned by libcrypto1.1-1.1.1q-r0.

Docker run expand parameter using variable defined using ARG

This is my simple Dockerfile. The issue is SCALA_VERSION variable in the line wget -q --no-cookies ... does not get interpolated. I am not sure how to fix that. I appreciate any help or hint.
ARG SCALA_MAJOR_VERSION="2.13"
ARG SCALA_MINOR_VERSION="7"
ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"
FROM openjdk:18-jdk-alpine AS base
LABEL version="$SCALA_VERSION"
WORKDIR /usr/lib
RUN apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies wget ca-certificates \
&& wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x \
&& apk del build-dependencies \
&& rm -rf /tmp/*
Logs:
➜ compiler-toolchain git:(master) ✗ docker build . -t cool
Sending build context to Docker daemon 16.54MB
Step 1/18 : ARG SCALA_MAJOR_VERSION="2.13"
Step 2/18 : ARG SCALA_MINOR_VERSION="7"
Step 3/18 : ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"
Step 4/18 : FROM openjdk:18-jdk-alpine AS base
---> c89120dcca4c
Step 5/18 : LABEL maintainer="boyland#uwm.edu"
---> Using cache
---> eb84f71065ca
Step 6/18 : LABEL version="$SCALA_VERSION"
---> Using cache
---> 23f11d22b6cb
Step 7/18 : WORKDIR /usr/lib
---> Using cache
---> 8762269e3700
Step 8/18 : RUN apk add --no-cache bash && apk add --no-cache --virtual=build-dependencies wget ca-certificates && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x && apk del build-dependencies && rm -rf /tmp/*
---> Running in 0cc02cf39a42
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ncurses-terminfo-base (6.3_p20211120-r0)
(2/4) Installing ncurses-libs (6.3_p20211120-r0)
(3/4) Installing readline (8.1.1-r0)
(4/4) Installing bash (5.1.8-r0)
Executing bash-5.1.8-r0.post-install
Executing busybox-1.34.1-r3.trigger
OK: 10 MiB in 24 packages
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/4) Installing libunistring (0.9.10-r1)
(2/4) Installing libidn2 (2.3.2-r0)
(3/4) Installing wget (1.21.2-r2)
(4/4) Installing build-dependencies (20211220.220536)
Executing busybox-1.34.1-r3.trigger
OK: 13 MiB in 28 packages
gunzip: invalid magic
tar: short read
The command '/bin/sh -c apk add --no-cache bash && apk add --no-cache --virtual=build-dependencies wget ca-certificates && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x && apk del build-dependencies && rm -rf /tmp/*' returned a non-zero code: 1
It's FROM openjdk:18-jdk-alpine AS base that does it. The ARGs set before you base on the new image aren't carried over. You need to move the ARG statements to after the FROM like this
FROM openjdk:18-jdk-alpine AS base
ARG SCALA_MAJOR_VERSION="2.13"
ARG SCALA_MINOR_VERSION="7"
ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"
LABEL version="$SCALA_VERSION"
WORKDIR /usr/lib
RUN apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies wget ca-certificates \
&& wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x \
&& apk del build-dependencies \
&& rm -rf /tmp/*

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 build command fails on COPY

Hi I have a docker file which is failing on the COPY command. It was running fine initially but then it suddenly crashed during the build process. The Docker file basically sets up the dev environment and authenticate with GCP.
FROM ubuntu:16.04
## ENV Variables
ENV PYTHON_VERSION="3.6.5"
ENV BUCKET_NAME='detection-sandbox'
ENV DIRECTORY='/usr/local/gcloud'
# Update and Install packages
RUN apt-get update -y \
&& apt-get install -y \
curl \
wget \
tar \
xz-utils \
bc \
build-essential \
cmake \
curl \
zlib1g-dev \
libssl-dev \
libsqlite3-dev \
python3-pip \
python3-setuptools \
unzip \
g++ \
git \
python-tk
# Install Python 3.6.5
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz \
&& tar -xvf Python-${PYTHON_VERSION}.tar.xz \
&& rm -rf Python-${PYTHON_VERSION}.tar.xz \
&& cd Python-${PYTHON_VERSION} \
&& ./configure \
&& make install \
&& cd / \
&& rm -rf Python-${PYTHON_VERSION}
# Install pip
RUN curl -O https://bootstrap.pypa.io/get-pip.py \
&& python3 get-pip.py \
&& rm get-pip.py
# Add SNI support to Python
RUN pip --no-cache-dir install \
pyopenssl \
ndg-httpsclient \
pyasn1
## Download and Install Google Cloud SDK
RUN mkdir -p /usr/local/gcloud \
&& curl https://sdk.cloud.google.com > install.sh \
&& bash install.sh --disable-prompts --install-dir=${DIRECTORY}
# Adding the package path to directory
ENV PATH $PATH:${DIRECTORY}/google-cloud-sdk/bin
# working directory
WORKDIR /usr/src/app
COPY requirements.txt ./ \
testproject-264512-9de8b1b35153.json ./
It fails at this step :
Step 13/21 : COPY requirements.txt ./ testproject-264512-9de8b1b35153.json ./
COPY failed: stat /var/lib/docker/tmp/docker-builder942576416/testproject-264512-9de8b1b35153.json: no such file or directory
Any leads in this would be helpful.
How are you running docker build command?
In docker best practices I've read that docker fails if you try to build your image from stdin using -
Attempting to build a Dockerfile that uses COPY or ADD will fail if this syntax is used. The following example illustrates this:
# create a directory to work in
mkdir example
cd example
# create an example file
touch somefile.txt
docker build -t myimage:latest -<<EOF
FROM busybox
COPY somefile.txt .
RUN cat /somefile.txt
EOF
# observe that the build fails
...
Step 2/3 : COPY somefile.txt .
COPY failed: stat /var/lib/docker/tmp/docker-builder249218248/somefile.txt: no such file or directory
I've reproduced issue... Here is my Dockerfile:
FROM alpine:3.7
## ENV Variables
ENV PYTHON_VERSION="3.6.5"
ENV BUCKET_NAME='detection-sandbox'
ENV DIRECTORY='/usr/local/gcloud'
# working directory
WORKDIR /usr/src/app
COPY kk.txt ./ \
kk.2.txt ./
If I create image by running docker build -t testImage:1 [DOCKERFILE_FOLDER], docker creates image and works correctly.
However if I try the same command from stdin as:
docker build -t test:2 - <<EOF
FROM alpine:3.7
ENV PYTHON_VERSION="3.6.5"
ENV BUCKET_NAME='detection-sandbox'
ENV DIRECTORY='/usr/local/gcloud'
WORKDIR /usr/src/app
COPY kk.txt ./ kk.2.txt ./
EOF
I get the following error:
Step 1/6 : FROM alpine:3.7
---> 6d1ef012b567
Step 2/6 : ENV PYTHON_VERSION="3.6.5"
---> Using cache
---> 734d2a106144
Step 3/6 : ENV BUCKET_NAME='detection-sandbox'
---> Using cache
---> 18fba29fffdc
Step 4/6 : ENV DIRECTORY='/usr/local/gcloud'
---> Using cache
---> d926a3b4bc85
Step 5/6 : WORKDIR /usr/src/app
---> Using cache
---> 57a1868f5f27
Step 6/6 : COPY kk.txt ./ kk.2.txt ./
COPY failed: stat /var/lib/docker/tmp/docker-builder518467298/kk.txt: no such file or directory
It seems that docker build images from /var/lib/docker/tmp/ if you build image from stdin, thus ADD or COPY commands don't work.
Incorrect path in source is a common error.
Use
COPY ./directory/testproject-264512-9de8b1b35153.json /dir/
instead of
COPY testproject-264512-9de8b1b35153.json /dir/

dash on alpine linux (in 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

Resources