aurny2420289
aurny2420289

Reputation: 491

install libxml in docker with python container

I met a dependency of libxml issue, when create a docker container with python, installing dependencies lib from a ubuntu image :

# pull official base image
FROM python:3.8.0-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

FROM ubuntu:16.04
RUN apt-get update -y
RUN apt-get install g++ gcc libxml2 libxslt-dev -y
# install dependencies

FROM python:3.8.0-alpine
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . /usr/src/app/

getting this compilation output error :

Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

Upvotes: 1

Views: 5474

Answers (1)

C.Nivs
C.Nivs

Reputation: 13106

You are installing those packages in ubuntu, but not alpine. In the builder pattern you would need to copy over the files from the builder layer into the runtime layer. However, ubuntu != alpine, so compiled binaries will not work.

You will need to leverage the apk installer to add those packages to the alpine layer:

...
RUN apk update && apk add g++ gcc libxml2 libxslt-dev
RUN python -m pip install --upgrade pip
...

Upvotes: 2

Related Questions