我试图通过上的教程将Django与Postgres、Gunicorn和Nginx对接
https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
docker在第7步时,我遇到了一个错误,即,
步骤7/23:运行pip-wheel-no-cache-dir-no-deps-wheel-dir/usr/src/app/wheels-r-requirements。txt文件
我能够更新Dockerfile。prod克服了这个错误,但我在步骤21中遇到了另一个错误
步骤21/26:运行pip安装--无缓存/轮子/*
这是我更新的Dockerfile。戳
###########
# BUILDER #
###########
# pull official base image
FROM python:3.8.3-alpine as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev libffi-dev openssl-dev
# lint
RUN pip install --upgrade pip
# RUN pip install flake8
COPY . .
# RUN flake8 --ignore=E501,F401 .
# install dependencies
COPY ./requirements.txt .
RUN apk --update add \
build-base \
jpeg-dev \
zlib-dev
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.8.3-alpine
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup -S app && adduser -S app -G app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
下面是我得到的错误
Step 21/26 : RUN pip install --no-cache /wheels/*
---> Running in 2edb399fffff
Processing /wheels/DateTimeRange-1.0.0-py3-none-any.whl
Processing /wheels/Django-3.1-py3-none-any.whl
Processing /wheels/Jinja2-2.11.2-py2.py3-none-any.whl
Processing /wheels/Markdown-3.2.2-py3-none-any.whl
Processing /wheels/MarkupSafe-1.1.1-cp38-cp38-linux_x86_64.whl
Processing /wheels/Pillow-7.2.0-cp38-cp38-linux_x86_64.whl
Processing /wheels/asgiref-3.2.10-py3-none-any.whl
Processing /wheels/certifi-2020.6.20-py2.py3-none-any.whl
Processing /wheels/chardet-3.0.4-py2.py3-none-any.whl
Processing /wheels/coreapi-2.3.3-py2.py3-none-any.whl
Processing /wheels/coreschema-0.0.4-py3-none-any.whl
Processing /wheels/dj_database_url-0.5.0-py2.py3-none-any.whl
Processing /wheels/django_cors_headers-3.6.0-py3-none-any.whl
Processing /wheels/django_filter-2.3.0-py3-none-any.whl
Processing /wheels/django_import_export-2.3.0-py3-none-any.whl
Processing /wheels/django_microsoft_auth-2.4.0-py2.py3-none-any.whl
Processing /wheels/django_rest_swagger-2.1.0-py2.py3-none-any.whl
Processing /wheels/djangorestframework-3.11.1-py3-none-any.whl
Processing /wheels/djangorestframework_gis-0.14-py2.py3-none-any.whl
Processing /wheels/djangorestframework_jwt-1.11.0-py2.py3-none-any.whl
Processing /wheels/djangorestframework_simplejwt-4.3.0-py3-none-any.whl
Processing /wheels/drf_msal_jwt-0.4.0-py2.py3-none-any.whl
Processing /wheels/gunicorn-20.0.4-py2.py3-none-any.whl
Processing /wheels/idna-2.10-py2.py3-none-any.whl
Processing /wheels/importlib_metadata-1.7.0-py2.py3-none-any.whl
Processing /wheels/itypes-1.2.0-py2.py3-none-any.whl
Processing /wheels/openapi_codec-1.3.2-py3-none-any.whl
Processing /wheels/pandas-1.1.2-cp38-cp38-linux_x86_64.whl
Processing /wheels/psycopg2_binary-2.8.5-cp38-cp38-linux_x86_64.whl
Processing /wheels/pytz-2020.1-py2.py3-none-any.whl
Processing /wheels/requests-2.24.0-py2.py3-none-any.whl
Processing /wheels/simplejson-3.17.2-cp38-cp38-linux_x86_64.whl
Processing /wheels/smartsheet_python_sdk-2.105.1-py2.py3-none-any.whl
Processing /wheels/sqlparse-0.3.1-py2.py3-none-any.whl
Processing /wheels/uritemplate-3.0.1-py2.py3-none-any.whl
Processing /wheels/urllib3-1.25.10-py2.py3-none-any.whl
Processing /wheels/zipp-3.1.0-py3-none-any.whl
Collecting typepy[datetime]<2,>=1.0.0
Downloading typepy-1.1.2-py3-none-any.whl (30 kB)
Collecting python-dateutil<3,>=2.4.2
Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Requirement already satisfied: setuptools>=38.3.0 in /usr/local/lib/python3.8/site-packages (from DateTimeRange==1.0.0) (47.1.1)
Collecting diff-match-patch
Downloading diff_match_patch-20200713-py3-none-any.whl (61 kB)
Collecting tablib[html,ods,xls,xlsx,yaml]>=0.14.0
Downloading tablib-3.0.0-py3-none-any.whl (47 kB)
Collecting cryptography
Downloading cryptography-3.3.1.tar.gz (539 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-mytrl8h6/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.12; platform_python_implementation != '"'"'PyPy'"'"''
cwd: None
Complete output (127 lines):
WARNING: The directory '/home/app/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting setuptools>=40.6.0
Downloading setuptools-52.0.0-py3-none-any.whl (784 kB)
Collecting wheel
Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Collecting cffi>=1.12
Downloading cffi-1.14.4.tar.gz (471 kB)
Collecting pycparser
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Building wheels for collected packages: cffi
Building wheel for cffi (setup.py): started
Building wheel for cffi (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-qyffv65y
cwd: /tmp/pip-install-6fztua11/cffi/
Complete output (48 lines):
unable to execute 'gcc': No such file or directory
unable to execute 'gcc': No such file or directory
No working compiler found, or bogus compiler options passed to
the compiler from Python's standard "distutils" module. See
the error messages above. Likely, the problem is not related
to CFFI but generic to the setup.py of any Python package that
tries to compile C code. (Hints: on OS/X 10.8, for errors about
-mno-fused-madd see http://stackoverflow.com/questions/22313407/
Otherwise, see https://wiki.python.org/moin/CompLangPython or
the IRC channel #python on irc.freenode.net.)
Trying to continue anyway. If you are trying to install CFFI from
a build done in a different context, you can ignore this warning.
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/cffi
copying cffi/lock.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/__init__.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/commontypes.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/error.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/verifier.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/api.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/cparser.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/model.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/recompiler.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_embedding.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.8/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/c
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.8 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.8/c/_cffi_backend.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for cffi
Running setup.py clean for cffi
Failed to build cffi
Installing collected packages: setuptools, wheel, pycparser, cffi
Running setup.py install for cffi: started
Running setup.py install for cffi: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zfw6b2gn/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-mytrl8h6/overlay --compile --install-headers /tmp/pip-build-env-mytrl8h6/overlay/include/python3.8/cffi
cwd: /tmp/pip-install-6fztua11/cffi/
Complete output (48 lines):
unable to execute 'gcc': No such file or directory
unable to execute 'gcc': No such file or directory
No working compiler found, or bogus compiler options passed to
the compiler from Python's standard "distutils" module. See
the error messages above. Likely, the problem is not related
to CFFI but generic to the setup.py of any Python package that
tries to compile C code. (Hints: on OS/X 10.8, for errors about
-mno-fused-madd see http://stackoverflow.com/questions/22313407/
Otherwise, see https://wiki.python.org/moin/CompLangPython or
the IRC channel #python on irc.freenode.net.)
Trying to continue anyway. If you are trying to install CFFI from
a build done in a different context, you can ignore this warning.
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/cffi
copying cffi/lock.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/__init__.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/commontypes.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/error.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/verifier.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/api.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/cparser.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/model.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/recompiler.py -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_embedding.h -> build/lib.linux-x86_64-3.8/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.8/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/c
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.8 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.8/c/_cffi_backend.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6fztua11/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zfw6b2gn/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-mytrl8h6/overlay --compile --install-headers /tmp/pip-build-env-mytrl8h6/overlay/include/python3.8/cffi Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 21.0 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-mytrl8h6/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.12; platform_python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 21.0 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
接下来我该怎么办?
多亏了@DawidGacek的建议,我为这两个容器都添加了依赖项,现在它工作得很好。这是最后一个工作Dockerfile。prod[注意:我刚刚注释了flake8 lint checker,如果您需要相同的,只需取消注释即可]
###########
# BUILDER #
###########
# pull official base image
FROM python:3.8.3-alpine as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev libffi-dev openssl-dev
# install other dependencies
RUN apk --update add \
build-base \
jpeg-dev \
zlib-dev
# lint
# RUN pip install --upgrade pip
# RUN pip install flake8
# COPY . .
# RUN flake8 --ignore=E501,F401 .
# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.8.3-alpine
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup -S app && adduser -S app -G app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev libffi-dev openssl-dev
# install other dependencies
RUN apk update && apk add libpq
RUN apk --update add \
build-base \
jpeg-dev \
zlib-dev
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
本文向大家介绍解决执行docker daemon命令时出错的问题,包括了解决执行docker daemon命令时出错的问题的使用技巧和注意事项,需要的朋友参考一下 最近在工作中遇到了一个问题,在一开始执行docker daemon命令时总是会出错导致进程stop,按照网上的方法在/etc/fstab文件里添加了一行 这时Docker daemon可以起来了,但是有了新的问题——执行docker r
我在执行命令时出错
问题内容: 尝试构建时出现以下错误: Jenkins 2.7.1在Windows Server 2012 R2上运行(在Jenkins 2.7.4上发生了相同的错误)。我可以通过git命令行克隆仓库,没有任何问题。发生这种情况时,我可以在任务管理器屏幕快照中看到多个git进程树,如果我稍等片刻,我会在Jenkins中看到它。 问题答案: 罪魁祸首是Git插件。更新后开始工作。我正在使用2.5.3版
我在Docker中执行触摸命令时遇到问题。 'touch'不被识别为内部或外部命令、可操作程序或批处理文件。
我正在执行命令“cordova build”(完成以上设置后,举例说明了此链接Phonegap的命令行界面)。 但note.js返回以下错误: 从“android”平台的默认值生成config.xml 准备android项目 通过命令“cmd”/C C:\net\phoneGap\hello\platforms\android\cordova\BUILD 错误:生成android项目时出错。执行“
假设一个docker容器用'docker run'运行,然后用'docker stop'停止。“docker start”之后会执行“cmd”命令吗?