I am trying to build a dockerfile but the problem is when it trying to build specifically cryptography is not building.
MY Dockerfile
FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1
RUN apk update \
# psycopg2 dependencies
&& apk add --virtual build-deps gcc python3-dev musl-dev\
&& apk add postgresql-dev \
&& apk add build-base \
# Pillow dependencies
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# CFFI dependencies
&& apk add libffi-dev py-cffi \
# Translations dependencies
&& apk add gettext \
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
&& apk add postgresql-client \
# cairo
&& apk add cairo cairo-dev pango-dev gdk-pixbuf-dev poppler-utils
# fonts for weasyprint
RUN mkdir ~/.fonts
COPY ./fonts/* /root/.fonts/
# secret key (should be in docker-secrets, or we need to run minikube locally
RUN mkdir /etc/secrets
COPY secret.readme proxy_rsa_key* /etc/secrets/
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/local/django/entrypoint /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r//' /start
RUN chmod +x /start
COPY ./compose/local/django/celery/worker/start /start-celeryworker
RUN sed -i 's/\r//' /start-celeryworker
RUN chmod +x /start-celeryworker
COPY ./compose/local/django/celery/beat/start /start-celerybeat
RUN sed -i 's/\r//' /start-celerybeat
RUN chmod +x /start-celerybeat
COPY ./compose/local/django/celery/flower/start /start-flower
RUN sed -i 's/\r//' /start-flower
RUN chmod +x /start-flower
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
when I try to build my dockerfile it shows:
Building wheel for cryptography (PEP 517): finished with status 'error'
ERROR: Command errored out with exit status 1:
error: Can not find Rust compiler
----------------------------------------
ERROR: Failed building wheel for cryptography
I tried to solve but i couldn't. I am newbie in docker.Please help how to get rid of this problem.
cryptography < 3.5:
You can skip the rust installation and other related dependencies by adding the line below before apk add commands:
ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
cryptography >= 3.5: Thanks #riptusk331
After this version rust will be required. Either install a specific version <3.5 or follow cryptography installation instructions. It is stated in the attached link that they are very aggressively explained in the docs.
Since the error is...
error: Can not find Rust compiler
...the solution is to install the rust compiler. You'll also need
cargo, the Rust package manager, and it looks like your Dockerfile
is missing openssl-dev.
The following builds successfully for me:
FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1
RUN apk add --update \
build-base \
cairo \
cairo-dev \
cargo \
freetype-dev \
gcc \
gdk-pixbuf-dev \
gettext \
jpeg-dev \
lcms2-dev \
libffi-dev \
musl-dev \
openjpeg-dev \
openssl-dev \
pango-dev \
poppler-utils \
postgresql-client \
postgresql-dev \
py-cffi \
python3-dev \
rust \
tcl-dev \
tiff-dev \
tk-dev \
zlib-dev
RUN pip install cryptography
Note that the above apk add ... command line is largely the same as
what you've got; I've just simplified the multiple apk add ...
statements into a single apk add execution.
pip install -U pip is what all I had to do
Some people might come here (Like I did) looking for a fix just for Python, not necessarily Alpine.
Several options are available, mentioned in the github issue. (only pick one of these)
You can install rust, as another answer mentioned
You can downgrade your cryptography version to 3.4.x
You can upgrade to pip version 19.1.1 or higher, which installs precompiled packages
I faced the same issue and in order to resolve it I tried out the following:
Answer provided by #larsks. RUN apk add cargo openssl-dev helped. But this resulted in a huge image size for me (>1GB). Best practice is to always target the bare-minimum with a small image size. This way, we don't expose ourselves to any external vulnerabilities.
Answer provided by Sabri Özgür, ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1. This worked great!
Based on the comment added by #riptusk331 for the earlier answer, simply ignoring the Rust build may only work for now, as Cryptography 3.5+ will start requiring Rust.
My solution just to be safe was;
...
ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
...
RUN pip install cryptography==3.4.6
...
This way, I managed to keep the image size at a considerably lower value while getting the build to pass.
Editing pyvenv.cfg by adding in my .env:
CRYPTOGRAPHY_DONT_BUILD_RUST=1
then doing pip install cryptography, solved my issue.
I am using windows 10 OS. I want to build an container based on linux so I can replicate code and dependencies developed from ubuntu. When I try to build it outputs Error message as above.
From my understanding docker for desktop runs linux OS kernel under-the-hood therefore allowing window users to run linux based containers, not sure why it is outputting this error.
My dockerfile looks like this:
FROM ubuntu:18.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt update \
&& apt install -y htop python3-dev wget
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir root/.conda \
&& sh Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh
RUN conda create -y -n ml python=3.7
COPY . src/
RUN /bin/bash -c "cd src \
&& source activate ml \
&& pip install -r requirements.txt"
requirements.txt contains:
apturl==0.5.2
asn1crypto==0.24.0
bleach==2.1.2
Brlapi==0.6.6
certifi==2020.11.8
chardet==3.0.4
click==7.1.2
command-not-found==0.3
configparser==5.0.1
cryptography==2.1.4
cupshelpers==1.0
dataclasses==0.7
When I run docker build command it outputs:
1.649 ERROR: Could not find a version that satisfies the requirement apturl==0.5.2 1.649 ERROR: No matching distribution found for apturl==0.5.2 Deleting it and running it lead to another error. All error seem to be associated with ubuntu packages.
Am I not running a ubuntu container? why aren't I allowed to install ubuntu packages?
Thanks!
You try to install ubuntu packages with pip (which is for python packages")
try apt install -y apturl
If you want to install python packages write pip install package_name
I am trying to create a simple docker image in AWS EC2.
I have the following Dockerfile.
FROM node:12-alpine
RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm
RUN mkdir -p /home/project/website/node_modules && chown -R node:node /home/project/website
WORKDIR /home/project/website
COPY /package*.json ./
USER node
RUN npm cache verify
RUN npm install
COPY --chown=node:node . .
RUN chmod +x wait-for.sh
RUN chmod -R 0755 /home/project/website/src/views/
EXPOSE 8000
when I try to build by this following command
docker-compose build
I got the following output
Step 2/12 : RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm
---> Running in 208f43729d68
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
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz: network error (check Internet connection and firewall)
autoconf (missing):
required by: world[autoconf]
automake (missing):
required by: world[automake]
build-base (missing):
required by: world[build-base]
gcc (missing):
required by: world[gcc]
libpng-dev (missing):
required by: world[libpng-dev]
libtool (missing):
required by: world[libtool]
nasm (missing):
required by: world[nasm]
zlib-dev (missing):
required by: world[zlib-dev]
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz: network error (check Internet connection and firewall)
ERROR: unsatisfiable constraints:
and I have already created it for the first time and everything was running successful, but I have changed some paths on my docker file and I have removed all containers, images, volumes...
but this time I got this error.
I solved the problem by the following commands
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d
Here is the original answer
My docker container has no internet
I am trying to pip install python-ldap in Docker but am missing lber.h. I need python-ldap because I am trying to implement an OS agnostic SSO for my application, following this for now and hoping it doesn't break the rest of my app https://code.tutsplus.com/tutorials/flask-authentication-with-ldap--cms-23101
I have tried
RUN apk add libsasl2-dev libldap2-dev libssl-dev
and
RUN apk --no-cache add libsasl2-dev libldap2-dev libssl-dev
but I get the following error:
ERROR: unsatisfiable constraints:
libldap2-dev (missing):
required by: world[libldap2-dev]
libsasl2-dev (missing):
required by: world[libsasl2-dev]
libssl-dev (missing):
required by: world[libssl-dev]
Having gone to https://pkgs.alpinelinux.org/packages?name=libldap2-dev&branch=edge I feel that it is possible that these packages do indeed not exist within the alpine python image. Therefore, I tried substituting the installations with packages that exist in the above link, namely: openssl libsasl libldap
This didn't work either and had the same effect as not installing any of the packages i.e. the header missing error appeared:
Modules/constants.h:7:10: fatal error: lber.h: No such file or directory
#include "lber.h"
^~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
as a result of /tmp/pip-install-doifa8k9/python-ldap/
My Dockerfile:
FROM python:3.8.0-alpine
WORKDIR /home/flask
ADD . /home/flask
RUN apk --no-cache add --update --virtual .build-editdistance gcc g++ && \
apk --no-cache add libsasl libldap openssl && \
apk --no-cache add --update --virtual .libs libstdc++ && \
apk add linux-headers && \
apk add unixodbc-dev;
RUN rm -rf /var/cache/apk/* && \
pip install --upgrade pip && \
pip install --upgrade setuptools && \
pip install --no-cache-dir -Ur requirements.txt && \
apk del .build-editdistance;
EXPOSE 5000
For alpine python in docker:
apk add openldap-dev
instead of
apk add libsasl libldap openssl
This is answered in I can't install python-ldap but the answer is buried sufficiently deep and obfuscated by the accepted answer ( which is where libsasl libldap openssl came from) that it would be a good idea to keep this docker specific question
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