In the below docker file:
FROM alpine:latest
ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH
RUN mkdir /root/bin /aws; \
apk add --no-cache groff less bash python jq curl py-pip tzdata
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk add --no-cache --virtual .build-deps gcc python2-dev python3-dev linux-headers musl-dev && \
pip install --upgrade pip; \
adduser samcli -Du 5566; \
chown -R samcli $HOME;
USER samcli
WORKDIR $HOME
RUN pip install --user --upgrade awscli aws-sam-cli;
USER root
RUN apk del .build-deps; \
rm -rf /var/cache/apk/*
Layer(RUN pip install --user --upgrade awscli aws-sam-cli;) is installing with python 2.7, despite image has python3.7 installed.
I see below deprecation error when installing python package:
Step 9/11 : RUN pip install --user --upgrade awscli aws-sam-cli;
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/
How to install aws package with python3.7?
because below command is using python2
pip install --user --upgrade awscli aws-sam-cli;
I would recommend using python offical image based on alpine so you will do not need to maintain and install the python version. Below base image is base on alpine 3.9 and python version is 3.7
FROM python:3.7-alpine3.9
ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk add --no-cache --virtual .build-deps python2-dev python3-dev gcc linux-headers musl-dev && \
adduser samcli -Du 5566; \
chown -R samcli $HOME;
RUN apk add --no-cache groff less bash jq curl py-pip tzdata
USER samcli
WORKDIR $HOME
RUN pip install --user --upgrade awscli aws-sam-cli;
USER root
RUN apk del .build-deps; \
rm -rf /var/cache/apk/*
This Dockerfile works for me.
FROM alpine:latest
RUN apk update && apk upgrade
RUN apk --no-cache add python3 py3-pip gcc musl-dev python3-dev
RUN pip install aws-sam-cli awscli
...
Related
This question already has answers here:
pg_config executable not found
(54 answers)
Closed 6 months ago.
i am trying to use docker in my django project, i am new to using docker and i do not really know where the error is coming from.
This is how my Dockerfile looks:
FROM python:3.8.13-slim-buster
WORKDIR /app
COPY ./my_app ./
RUN pip install --upgrade pip --no-cache-dir
RUN pip install psycopg2 --no-cache-dir
RUN apk del build-deps --no-cache-dir
RUN pip install -r /app/requirements.txt --no-cache-dir
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
# CMD ["gunicorn", "main_app.wsgi:application", "--bind"]
Hopefully you already know that:
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)
I installed Python 3.6 on Ubuntu 16.04 on Docker using the ppa:jonathonf/python-3.6 repository. Now I'd like to install xapian so I can use it with Python. I have not found any ready-made packages, so I am trying to build it from sources. I set PYTHON3 and PYTHON3_LIB parameters to point to Python 3.6. During the build process I get the following error:
ImportError: libxapian.so.30: cannot open shared object file: No such file or directory
I tried xapian versions 1.3.7 and 1.4.5 without luck.
How can I install xapian?
Here's a Dockerfile to reproduce my error:
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update \
&& apt-get install -y python3-pip docker.io python3.6 python3.6-dev software-properties-common \
python-software-properties build-essential wget unzip cmake python3-sphinx \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3.6 python
RUN python -m pip install --upgrade pip
# install xapian 1.4.5
RUN apt-get update && apt-get install -y curl uuid-dev zlib1g-dev
WORKDIR /root
RUN curl --silent --show-error --fail --next -O https://oligarchy.co.uk/xapian/1.4.5/xapian-core-1.4.5.tar.xz
RUN curl --silent --show-error --fail --next -O https://oligarchy.co.uk/xapian/1.4.5/xapian-bindings-1.4.5.tar.xz
RUN tar xvf xapian-core-1.4.5.tar.xz
RUN tar xvf xapian-bindings-1.4.5.tar.xz
WORKDIR /root/xapian-core-1.4.5
RUN ./configure && make && make install
WORKDIR /root/xapian-bindings-1.4.5
RUN ./configure PYTHON3=/usr/bin/python3.6 PYTHON3_LIB=/usr/lib/python3.6 --with-python3 && make && make install
RUN python -c "import xapian"
The problem is that the Xapian library (libxapian.so.30) is being installed into /usr/local/lib by default, but Ubuntu doesn't know that it's been put there yet. You can tell it by adding:
RUN ldconfig
after installing the core (so before you change WORKDIR to build the bindings).
There's some helpful information about ldconfig and library search paths on Ubuntu in the answers to this Unix Stackexchange question.
I am currently building an image from alpine:3.7.
There are two packages that I am having problems with:
pendulum (specifically python-dateutils package)
service_identity (specifically attrs package)
The error that I receive it is:
Could not find a version that satisfies the requirement setuptools (from versions: ) No matching distribution found for setuptools
Note: all packages are pre-cached on a directory using pip download.
The dockerfile looks as follows:
RUN apk add --no-cache --virtual .build-deps <dev packages>
&& apk add --no-cache --update python3
&& pip3 install --upgrade pip setuptools
RUN pip3 install -f ./python-packages --no-index -r requirements.txt ./python-packages/pkgs
....
dev-packages such as libffi-dev, libressl-dev, etc.
I'm not sure about the full list of dev-packages to build in the question, but it should be the following: g++ (GNU C++ standard library and compiler), python3-dev (python3 development files), libffi-dev (libffi development files) and openssl-dev (Toolkit for SSL v2/v3 and TLS v1 development files).
The Dockerfile is:
FROM alpine:3.7
RUN apk add --no-cache --virtual .build-deps g++ python3-dev libffi-dev openssl-dev && \
apk add --no-cache --update python3 && \
pip3 install --upgrade pip setuptools
RUN pip3 install pendulum service_identity
Apparently when upgrading pip with:
pip3 install --upgrade pip setuptools
I removed pip upgrading and installation worked. Now, I have been researching the correct way to upgrade pip on alpine and found a Dockerfile in a github repo that does this check:
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
Which makes sure that pip3 is being referred when calling just pip command by doing a symbolic link on python and system binaries' directories.
I got this error when i run command
sudo docker-compose up
Docker File:
FROM alpine
ARG AWS_RDS_USER
ARG AWS_RDS_PASSWORD
ARG AWS_RDS_HOST
ARG AWS_RDS_DATABASE
ARG LOCALE_SERVICE_URL
ARG CRYPTO_KEY
ENV APP_DIR=/app
ENV APP_ENV=production
ENV DATABASE_CONNECTION_STRING=mysql://${AWS_RDS_USER}:${AWS_RDS_PASSWORD}#${AWS_RDS_HOST}/${AWS_RDS_DATABASE}
ENV LOCALE_SERVICE_URL=$LOCALE_SERVICE_URL
ENV CRYPTO_KEY=$CRYPTO_KEY
COPY build/requirements.txt build/app.ini ${APP_DIR}/
COPY build/nginx.conf /etc/nginx/nginx.conf
COPY api ${APP_DIR}/api
RUN apk add --no-cache curl python pkgconfig python-dev openssl-dev libffi-dev musl-dev make gcc
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python
RUN apk update && \
apk add --virtual .build-deps autoconf gcc make g++ python-dev && \
apk add nginx uwsgi uwsgi-python py2-pip py-mysqldb && \
chown -R nginx:nginx ${APP_DIR} && \
chmod 777 /run/ -R && \
chmod 777 /root/ -R && \
pip2 install --upgrade pip && \
pip2 install -r ${APP_DIR}/requirements.txt && \
apk del .build-deps && \
rm -fR tmp/* && \
pw_migrate migrate --database=$DATABASE_CONNECTION_STRING --directory=$APP_DIR/api/migrations -v
EXPOSE 80
CMD nginx && uwsgi --ini ${APP_DIR}/app.ini
For solution, I tried to install below packages
1) gcc package.
2) libffi packages.
3) pip openssl packages.
But still error is not resolved. Any help should be appreciated
Try the solution suggested here
This is because you need a working compiler, the easiest way around
this is too install the build-base package like so:
apk add --no-cache --virtual .pynacl_deps build-base python3-dev
libffi-dev This will install various tools that are required to
compile pynacl and pip install pynacl will now succeed.
Note it is optional to use the --virtual flag but it makes it easy to
trim the image because you can run apk del .pynacl_deps later in your
dockerfile as they are not needed any more and would reduce the
overall size of the image.
To use PostgreSql in python I need to
pip install psycopg2
However, it has dependency on libpq-dev and python-dev. I wonder how can I install the dependencies in alpine? Thanks.
Here is a Dockerfile:
FROM python:2.7-alpine
RUN apk add python-dev libpq-dev
RUN pip install psycopg2
and the output is:
Step 3 : RUN apk add python-dev libpq-dev ---> Running in
3223b1bf7cde WARNING: Ignoring APKINDEX.167438ca.tar.gz: No such file
or directory WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file
or directory ERROR: unsatisfiable constraints: libpq-dev (missing):
required by: world[libpq-dev] python-dev (missing):
required by: world[python-dev] ERROR: Service 'service' failed to build: The command '/bin/sh -c apk add python-dev libpq-dev' returned
a non-zero code: 2
If you only need to install psycopg2 for python 2.7 on Docker image based on python:2.7-alpine then following code for Dockerfile will be nice for you:
FROM python:2.7-alpine
RUN apk update && \
apk add --virtual build-deps gcc python-dev musl-dev && \
apk add postgresql-dev
RUN pip install psycopg2
An explanation before compile/install psycopg2
libpq is the client library for PostgreSQL
postgresql-dev are the package with the source headers to link libpq in a library/binary in a compilation, in this case when pip compiles psycopg .
I use the following configuration in alpine 3.7, I add some comments to explain it.
# Installing client libraries and any other package you need
RUN apk update && apk add libpq
# Installing build dependencies
# For python3 you need to add python3-dev *please upvote the comment
# of #its30 below if you use this*
RUN apk add --virtual .build-deps gcc python-dev musl-dev postgresql-dev
# Installing and build python module
RUN pip install psycopg2
# Delete build dependencies
RUN apk del .build-deps
Had problems with running Python 3.7 and PostgreSQL under Alpine Linux in Docker.
This article helped https://www.rockyourcode.com/install-psycopg2-binary-with-docker/
The main thing is to reference psypcopg2-binary in your requirements file and install the following packages (in Dockerfile):
RUN apk update && \
apk add --no-cache --virtual build-deps gcc python3-dev musl-dev && \
apk add postgresql-dev
I couldn't get it to install from python:2.7.13-alpine. Ended up with this:
FROM gliderlabs/alpine:3.3
RUN apk add --no-cache --update \
python \
python-dev \
py-pip \
build-base
RUN apk add --virtual build-deps gcc python-dev musl-dev && \
apk add --no-cache --update postgresql-dev && \
pip install psycopg2==2.7.1
Seems like the package you need is libpq not libpq-dev:
https://pkgs.alpinelinux.org/package/edge/main/x86/py2-psycopg2
Have a look at the dependencies at the right
add it in dockerfile
RUN apk update && apk add --no-cache --virtual .build-deps\
postgresql-dev gcc libpq python3-dev musl-dev linux-headers\
&& pip install --no-cache-dir -r requirements.txt\
&& apk del .build-deps\
&& rm -rf /var/cache/apk/*
What helped me was:
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& apk add build-base \
&& apk add gcc musl-dev libffi-dev openssl-dev python3-dev \
&& apk add postgresql-dev \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
RUN pip install --trusted-host pypi.python.org psycopg2
Especially apk add gcc musl-dev libffi-dev openssl-dev python3-dev as indicated in Docker: Installing python cryptography on alpine linux distribution
This may have to something with blockage of some countries by docker so you may sure you are using vpn