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 \ # && 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.
6 Answers
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.
3Since 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
cryptographyversion 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-devhelped. 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.