我正在尝试将docker镜像迁移到基于alpine的镜像,但是遇到一个问题,我无法在镜像构建期间编译消息。
FROM python:3.6-alpine
ENV PYTHONUNBUFFERED 1
# Creating working directory
RUN mkdir /code
WORKDIR /code
# Copying requirements
COPY ./myproject/ .
RUN apk add --no-cache --virtual .build-deps \
ca-certificates gcc postgresql-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps
RUN python manage.py compilemessages
我唯一的问题是在编译消息的步骤中。这里的错误
CommandError: Can't find msgfmt. Make sure you have GNU gettext tools 0.15 or newer installed.
答案 0 :(得分:0)
您需要将gettext
添加到dockerfile中。您可以使用:RUN apk add gettext
进行添加。还有Alpine软件包链接:https://pkgs.alpinelinux.org/package/edge/main/x86/gettext
答案 1 :(得分:0)
这是我在项目中使用的apline3.8的Dockerfile,它适用于makemessages
和compilemessages
。
FROM python:3.6-alpine3.8
# postgresql-client is required by psql
# postgresql-dev musl-dev gcc are required by psycopg
# NOTE: there is py3-psycopg2
# linux-headers is required by uwsgi
# gettext-dev is required by ./manage.py makemessages
# TODO: optimize installation by using --virtual
RUN apk update && apk upgrade \
&& apk add postgresql-client \
postgresql-dev \
musl-dev \
gcc \
linux-headers \
gettext-dev \
&& pip install pipenv
ENV PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8
COPY docker/backend/docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
WORKDIR /project/backend
COPY backend/Pipfile backend/Pipfile.lock /project/backend/
# TODO: use virtualenv?
RUN pipenv install --system --ignore-pipfile --dev
答案 2 :(得分:0)
我知道这个答案很旧,但是希望我的答案会有所帮助。
您首先创建--virtual软件包并安装它们。这对您的容器非常有用,因为它既小又干净,但是 问题在这里
&& apk del .build-deps
使用此命令删除所有虚拟软件包。如果gettext-dev
在这里
RUN apk add --no-cache --virtual .build-deps \
ca-certificates gcc postgresql-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev gettext-dev\
它也将被删除。 因此,如果您希望软件包保留在容器中,则需要在安装主软件包后将其添加。
例如
FROM python:3.6-alpine
ENV PYTHONUNBUFFERED 1
# Creating working directory
RUN mkdir /code
WORKDIR /code
# Copying requirements
COPY ./myproject/ .
RUN apk add --no-cache --virtual .build-deps \
ca-certificates gcc postgresql-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps
RUN apk add gettext-dev
RUN python manage.py compilemessages
或者您可以删除此行
&& apk del .build-deps
但这意味着您的容器将更大。