ERROR: unsatisfiable constraints using apk in dockerfile - docker

I'm trying to install postgis into a postgres container.
Dockerfile:
FROM postgres:9.6.4-alpine
RUN apk update \
&& apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts \
&& rm -rf /var/lib/apt/lists/*
COPY ./scripts/postgis.sh /docker-entrypoint-initdb.d/postgis.sh
postgis.sh:
#!/bin/sh
for DB in $(psql -t -c "SELECT datname from pg_database where datname = 'backend'"); do
echo "Loading PostGIS extensions into $DB"
"${psql[#]}" --dbname="$DB" <<-'EOSQL'
CREATE EXTENSION IF NOT EXISTS postgis;
EOSQL
done
I got this error:
ERROR: unsatisfiable constraints:
postgresql-9.6-postgis-2.4 (missing):
required by:
world[postgresql-9.6-postgis-2.4]
postgresql-9.6-postgis-2.4-scripts (missing):
required by:
world[postgresql-9.6-postgis-2.4-scripts]
The command '/bin/sh -c apk update && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 2
I found similar questions such as :
ERROR: unsatisfiable constraints: while installing package in alpine
ERROR: unsatisfiable constraints - on php:7-fpm-alpine
But it doesn't solve my problem.How can I add postgis extension to my postgres container with apk?

Postgis package is only available in edge alpine repo, not in a stable one. That's why you are getting "unsatisfiable constraints" error.
But anyway you can install postgis from edge repo:
# echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
WARNING: This apk-tools is OLD! Some packages might not function properly.
v3.5.2-254-g9d4623dc57 [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
v3.5.2-247-gc85efb30e1 [http://dl-cdn.alpinelinux.org/alpine/v3.5/community]
v3.7.0-2163-ge03552fc58 [http://dl-cdn.alpinelinux.org/alpine/edge/testing]
OK: 10930 distinct packages available
# apk search --no-cache postgis
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
WARNING: This apk-tools is OLD! Some packages might not function properly.
postgis-dev-2.4.1-r1
postgis-2.4.1-r1
postgis-doc-2.4.1-r1
So, the final Dockerfile is:
FROM postgres:9.6.4-alpine
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update \
&& apk add -u postgis \
&& rm -rf /var/lib/apt/lists/*
COPY ./scripts/postgis.sh /docker-entrypoint-initdb.d/postgis.sh
UPDATED on January 23th 2020:
Postgis is available in main and community repositories starting from Alpine version 3.11:
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.11.3
PRETTY_NAME="Alpine Linux v3.11"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/ #
/ # apk search --no-cache postgis
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
postgis-3.0.0-r1
postgis-doc-3.0.0-r1
You don't need to use edge repo testing branch for Alpine version 3.11 and later.

Old:
apk add --no-cache curl jq python py-pip
New:
apk add --no-cache curl jq python3 py3-pip

It is weird but in my case solution was as simple as to run:
sudo systemctl restart docker
... on a machine where you running docker containers

Related

Visual studio code docker container error

I want to use a docker container with VS code. I added configuration files for Anaconda configuration container and build it. VS Code created a dockerfile:
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/python-3-anaconda/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/anaconda:0-3
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
# Copy environment.yml (if found) to a temp location so we update the environment. Also
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
&& rm -rf /tmp/conda-tmp
RUN apt-get update
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
But when I add command RUN apt-get or any another command (for example: RUN pip3 install opencv-python) at the and of this dockerfile then I get an error: "An error occurred setting up the container."
It is very strange problem. This commands are correctly, but I can't to change original dockerfile. After any change in the dockerfile I get this error. What is way to solve this problem? I want to ask for some examples of correct dockerfiles with right pip3 packages installation.
Also I want to ask. Where does VS code keep created docker images?

luarocks install returned a non-zero code: 132 (installing kong)

I am trying with https://github.com/d4rkstar/kong-konga-keycloak when I run sudo docker-compose up -d kong it send me:
The command '/bin/sh -c luarocks install --pin lua-resty-jwt' returned a non-zero code: 132
Watching dockerfile it contains:
FROM kong:2.0.4-alpine
LABEL description="Alpine + Kong 2.0.4 + kong-oidc plugin"
USER root
RUN apk update && apk add git unzip luarocks
RUN luarocks install --pin lua-resty-jwt 0.2.2-0
RUN luarocks install kong-oidc
USER kong
This is the output when I install manually:
/ # apk add luarocks
(1/2) Installing curl (7.79.1-r0)
(2/2) Installing luarocks (2.4.4-r1)
Executing busybox-1.31.1-r9.trigger
OK: 67 MiB in 38 packages
/ # luarocks
Illegal instruction (core dumped)
My platform is: ubuntu 20 where I am running docker 20.10.10 and docker-compose 1.29.2.
2 days after
I replaced apk add luarocks by ( How to install gdbserver package on Alpine Docker image? )
RUN apk add --no-cache make
RUN apk add --no-cache linux-headers
RUN apk add --no-cache texinfo
RUN apk add --no-cache gcc
RUN apk add --no-cache g++
RUN apk add --no-cache gfortran
# install gdb
# RUN apk add --no-cache gdb
RUN mkdir gdb-build ;\
cd gdb-build;\
wget http://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.xz;\
tar -xvf gdb-7.11.tar.xz;\
cd gdb-7.11;\
./configure --prefix=/usr;\
make;\
make -C gdb install;\
cd ..;\
rm -rf gdb-build/;
then now I do not get error while I build.
I get the same error when I tried to migrate:
docker-compose run --rm kong kong migrations bootstrap
and kong never start, but now luarocks works fine inside container.
Thank you

Docker node js issues: sudo not found

I am having issues with building my docker file with Azure DevOps.
Here is a copy of my docker file:
FROM node:10-alpine
# Create app directory
WORKDIR /usr/src/app
# Copy app
COPY . .
# install packages
RUN apk --no-cache --virtual build-dependencies add \
git \
python \
make \
g++ \
&& sudo npm#latest -g wait-on concurrently truffle \
&& npm install \
&& apk del build-dependencies \
&& truffle compile --all
# Expose the right ports, the commands below are irrelevant when using a docker-compose file.
EXPOSE 3000
CMD ["npm", "run", "server”]
it was working recently now I am getting the following error message:
sudo not found.
What is the cause of this sudo not found error?
Don't use sudo. Just drop that from the command. That image is already running as root by default - there's no reason for it.
TJs-MacBook-Pro:~ tj$ docker run node:10-alpine whoami
root

Alpine unsatisfiable constraints: missing packages

I am trying to create a docker image based on alpine:3.7, but I get errors while installing some packages with apk add.
Example:
ERROR: unsatisfiable constraints:
apache2-suexec (missing):
required by: world[apache2-suexec-custom]
host (missing):
required by: world[host]
lpr (missing):
required by: world[lpr]
time (missing):
required by: world[time]
The cause is that these packages do not exist in alpine repositories yet. How can I solve these issues? Is there any repository from which I can download them?
I'm using this line
FROM alpine:3.7
RUN apk update \
&& apk upgrade \
&& apk --no-cache add --update tcl apache2 apache2-suexec ca-certificates \
apk-tools curl build-base supervisor lpr time dcron host rsync libxml2-utils libxslt
You have an issue with the following packages: apache2-suexec, host, lpr and time.
Alpine has some other package structure than main Linux OSs:
apache2-suexec is a part of apache2 package;
host is a part of bind-tools package;
lpr is a part of cups-client package;
time is already in alpine image. It uses busybox's time utility.
So, the final Dockerfile is:
FROM alpine:3.7
RUN apk update \
&& apk upgrade \
&& apk --no-cache add --update tcl apache2 ca-certificates \
apk-tools curl build-base supervisor cups-client dcron bind-tools rsync libxml2-utils libxslt

Docker + older version of Elixir/Phoenix

I have been requested to move an Elixir/Phoenix app to Docker, with which I have no prior experience. The app uses non-latest versions of Elixir and Phoenix so I have had to diverge from the code online which generally focuses on latest versions. That led me to write this Dockerfile
# FROM bitwalker/alpine-elixir:latest
FROM bitwalker/alpine-elixir:1.3.4
MAINTAINER Paul Schoenfelder <paulschoenfelder#gmail.com>
# Important! Update this no-op ENV variable when this Dockerfile
# is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT=2017-07-26 \
# Set this so that CTRL+G works properly
TERM=xterm
# Install NPM
RUN \
mkdir -p /opt/app && \
chmod -R 777 /opt/app && \
apk update && \
apk --no-cache --update add \
git make g++ wget curl inotify-tools \
nodejs nodejs-current-npm && \
npm install npm -g --no-progress && \
update-ca-certificates --fresh && \
rm -rf /var/cache/apk/*
# Add local node module binaries to PATH
ENV PATH=./node_modules/.bin:$PATH \
HOME=/opt/app
# Install Hex+Rebar
RUN mix local.hex --force && \
mix local.rebar --force
WORKDIR /opt/app
CMD ["/bin/sh"]
<then it goes on to add some elixir depedencies>
On running
sudo docker build -t phoenix .
I'm ending up with this error and wondering how to get around it? Noting 'current' in the title I'm wondering whether using an older version of nodejs, and if so, how to do that? Beyond that I am open to any and all suggestions
ERROR: unsatisfiable constraints:
nodejs-current-npm (missing):
required by: world[nodejs-current-npm]
musl-1.1.14-r14:
breaks: musl-dev-1.1.14-r15[musl=1.1.14-r15]
That looks like bitwalker/alpine-elixir issue 5:
when using tagged images, you may sometimes need to explicitly upgrade packages, as the installed packages are at the versions found when building the image.
Generally it's as simple as adding apk --update upgrade before any commands which install packages.
Indeed, when you compare the old elixir 1.4.4-based Dockerfile, and the latest one, you will see an upgrade first in the latter:
apk --no-cache --update upgrade && \
apk add --no-cache --update --virtual .elixir-build \
...
Try and add that to your Dockerfile.

Resources