Django-无法在Alpine中编译消息? [英] Django - Cannot compilemessages in Alpine?

查看:68
本文介绍了Django-无法在Alpine中编译消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将docker镜像迁移到基于alpine的镜像,但遇到一个问题,即在镜像构建期间无法编译消息.

I'm trying to migrating our docker image to alpine based, but I got a problem that I cannot compile messages during image building.

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

我唯一的问题是在编译消息的步骤中.这里的错误

The only problem I have is in the step compiling messages. Here the error

CommandError: Can't find msgfmt. Make sure you have GNU gettext tools 0.15 or newer installed.

推荐答案

我知道这个答案很旧,但是希望我的答案会有所帮助.

I know that this answer is old, but hope that my answer will help.

您首先创建--virtual软件包,然后安装它们.这对您的容器非常有用,因为它既小又干净,但是问题在这里

You create --virtual packages at the beginning and install them. It's great for your container, because it stays small and clean, but problem is here

&& apk del .build-deps

使用此命令删除所有虚拟软件包.如果 gettext-dev 在这里

With this command you delete all virtual packages. If gettext-dev was here

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\

它也将被删除.因此,如果您希望软件包保留在容器中,则需要在安装主软件包后将其添加.

It also be deleted. So if you want that your package stayed inside container you need to add it after main packages install.

例如

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

但这意味着您的容器将更大.

but this means that your container will be much bigger.

这篇关于Django-无法在Alpine中编译消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆