首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Docker-组合生成失败的服务'web‘失败生成

Docker-组合生成失败的服务'web‘失败生成
EN

Stack Overflow用户
提问于 2022-10-18 05:35:09
回答 1查看 146关注 0票数 1

我刚开始使用dockerfile和dockerfile进行对接和部署。这个模块使用的是烧瓶和MySQL。当试图使用docker构建web映像时,它失败了。我不知道怎么回事,任何帮助都会很感激

项目结构

码头工

代码语言:javascript
运行
复制
version: "3.9"
    
    x-user-module: &app-container
      build:
        context: "../"
        dockerfile: "./deploy/dockerfile"
        target: development
      restart: always
    
    services:
      web:
        <<: *app-container
        links:
          - mysql
        ports:
          - "8000:8000"
        environment:
          - HOST
        command: >
          sh -c "uwsgi --ini uwsgi.ini"
    
    
  mysql:
    image: mysql:8.0.31
    ports:
      - "3306:3306"
    environment:
      - MYSQL_HOST
      - MYSQL_DB
      - MYSQL_PASSWORD
      - MYSQL_USER

    volumes:
      - ./db:/docker-entrypoint-initdb.d/:ro

文档

代码语言:javascript
运行
复制
# Dockerfile
    # Uses multi-stage builds requiring Docker 17.05 or higher
    # See https://docs.docker.com/develop/develop-images/multistage-build/
    
    # Creating a python base with shared environment variables
    FROM python:3.10-slim as python-base
    ENV PYTHONUNBUFFERED=1 \
        PYTHONDONTWRITEBYTECODE=1 \
        PIP_NO_CACHE_DIR=off \
        PIP_DISABLE_PIP_VERSION_CHECK=on \
        PIP_DEFAULT_TIMEOUT=100 \
        POETRY_HOME="/opt/poetry" \
        POETRY_VIRTUALENVS_IN_PROJECT=true \
        POETRY_NO_INTERACTION=1 \
        PYSETUP_PATH="/opt/pysetup" \
        VENV_PATH="/opt/pysetup/.venv"
    
    ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
    
    
    # builder-base is used to build dependencies
    FROM python-base as builder-base
    RUN apt-get update \
        && apt-get install --no-install-recommends -y \
            curl \
            build-essential
    
    # Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
    ENV POETRY_VERSION=1.2.2
    RUN curl -sSL https://install.python-poetry.org | python
    
    # We copy our Python requirements here to cache them
    # and install only runtime deps using poetry
    WORKDIR $PYSETUP_PATH
    COPY ./poetry.lock ./pyproject.toml ./
    RUN poetry install --no-dev  # respects
    
    # 'development' stage installs all dev deps and can be used to develop code.
    # For example using docker-compose to mount local volume under /app
    FROM python-base as development
    
    # Copying poetry and venv into image
    COPY --from=builder-base $POETRY_HOME $POETRY_HOME
    COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
    
    # venv already has runtime deps installed we get a quicker install
    WORKDIR $PYSETUP_PATH
    RUN poetry install
    
    WORKDIR /
    COPY ./src /app
    COPY ./src/uwsgi.ini /app/uwsgi.ini
    
    WORKDIR /app/

命令行输出

代码语言:javascript
运行
复制
            => [builder-base 3/5] WORKDIR /opt/pysetup                                                                                                                                       0.0s
     => [builder-base 4/5] COPY ./poetry.lock ./pyproject.toml ./                                                                                                                     0.0s
     => ERROR [builder-base 5/5] RUN poetry install  # respects                                                                                                                       9.7s
    ------
     > [builder-base 5/5] RUN poetry install  # respects:
    #10 0.950 Creating virtualenv flask-user-module in /opt/pysetup/.venv
    #10 1.954 Installing dependencies from lock file
    #10 2.157
    #10 2.157 Package operations: 11 installs, 0 updates, 0 removals
    #10 2.157
    #10 2.158   • Installing markupsafe (2.1.1)
    #10 3.916   • Installing click (8.1.3)
    #10 3.918   • Installing itsdangerous (2.1.2)
    #10 3.921   • Installing jinja2 (3.1.2)
    #10 3.924   • Installing werkzeug (2.2.2)
    #10 5.534   • Installing flask (2.2.2)
    #10 5.534   • Installing mysqlclient (2.1.1)
    #10 5.538   • Installing pymysql (1.0.2)
    #10 9.285
    #10 9.285   CalledProcessError
    #10 9.285
    #10 9.285   Command '['/opt/pysetup/.venv/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/opt/pysetup/.venv', '--no-deps', '/root/.cache/pypoetry/artifacts/af/19/9f/f71f7f0d313981e3dce1608dc021f6f4a338dd61aa21f8e1bbeb8a1deb/mysqlclient-2.1.1.tar.gz']' returned non-zero exit status 1.
    #10 9.285
    #10 9.285   at /usr/local/lib/python3.10/subprocess.py:526 in run
    #10 9.357        522│             # We don't call process.wait() as .__exit__ does that for us.
    #10 9.357        523│             raise
    #10 9.357        524│         retcode = process.poll()
    #10 9.358        525│         if check and retcode:
    #10 9.358     →  526│             raise CalledProcessError(retcode, process.args,
    #10 9.358        527│                                      output=stdout, stderr=stderr)
    #10 9.358        528│     return CompletedProcess(process.args, retcode, stdout, stderr)
    #10 9.358        529│
    #10 9.358        530│
    #10 9.358
    #10 9.358 The following error occurred when trying to handle this error:
    #10 9.359
    #10 9.359
    #10 9.359   EnvCommandError
    #10 9.359
    #10 9.360   Command ['/opt/pysetup/.venv/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/opt/pysetup/.venv', '--no-deps', '/root/.cache/pypoetry/artifacts/af/19/9f/f71f7f0d313981e3dce1608dc021f6f4a338dd61aa21f8e1bbeb8a1deb/mysqlclient-2.1.1.tar.gz'] errored with the following return code 1, and output:
    #10 9.360   Processing /root/.cache/pypoetry/artifacts/af/19/9f/f71f7f0d313981e3dce1608dc021f6f4a338dd61aa21f8e1bbeb8a1deb/mysqlclient-2.1.1.tar.gz
    #10 9.360     Installing build dependencies: started
    #10 9.360     Installing build dependencies: finished with status 'done'
    #10 9.360     Getting requirements to build wheel: started
    #10 9.360     Getting requirements to build wheel: finished with status 'error'
    #10 9.360     error: subprocess-exited-with-error
    #10 9.360
    #10 9.360     × Getting requirements to build wheel did not run successfully.
    #10 9.360     │ exit code: 1
    #10 9.360     ╰─> [27 lines of output]
    #10 9.360         mysql_config --version
    #10 9.360         /bin/sh: 1: mysql_config: not found
    #10 9.360         mariadb_config --version
    #10 9.360         /bin/sh: 1: mariadb_config: not found
    #10 9.360         mysql_config --libs
    #10 9.360         /bin/sh: 1: mysql_config: not found
    #10 9.360         Traceback (most recent call last):
    #10 9.360           File "/opt/pysetup/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
    #10 9.360             main()
    #10 9.360           File "/opt/pysetup/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
    #10 9.360             json_out['return_val'] = hook(**hook_input['kwargs'])
    #10 9.360           File "/opt/pysetup/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
    #10 9.360             return hook(config_settings)
    #10 9.360           File "/tmp/pip-build-env-xebq6tlg/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
    #10 9.360             return self._get_build_requires(config_settings, requirements=['wheel'])
    #10 9.360           File "/tmp/pip-build-env-xebq6tlg/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
    #10 9.360             self.run_setup()
    #10 9.360           File "/tmp/pip-build-env-xebq6tlg/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 483, in run_setup
    #10 9.360             super(_BuildMetaLegacyBackend,
    #10 9.360           File "/tmp/pip-build-env-xebq6tlg/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
    #10 9.360             exec(code, locals())
    #10 9.360           File "<string>", line 15, in <module>
    #10 9.360           File "/tmp/pip-req-build-xvtg4k3u/setup_posix.py", line 70, in get_config
    #10 9.360             libs = mysql_config("libs")
    #10 9.360           File "/tmp/pip-req-build-xvtg4k3u/setup_posix.py", line 31, in mysql_config
    #10 9.360             raise OSError("{} not found".format(_mysql_config_path))
    #10 9.360         OSError: mysql_config not found
    #10 9.360         [end of output]
    #10 9.360
    #10 9.360     note: This error originates from a subprocess, and is likely not a problem with pip.
    #10 9.360   error: subprocess-exited-with-error
    #10 9.360
    #10 9.360   × Getting requirements to build wheel did not run successfully.
    #10 9.360   │ exit code: 1
    #10 9.360   ╰─> See above for output.
    #10 9.360
    #10 9.360   note: This error originates from a subprocess, and is likely not a problem with pip.
    #10 9.360
    #10 9.360
    #10 9.360   at /opt/poetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1476 in _run
    #10 9.428       1472│                 output = subprocess.check_output(
    #10 9.428       1473│                     command, stderr=subprocess.STDOUT, env=env, **kwargs
    #10 9.428       1474│                 )
    #10 9.428       1475│         except CalledProcessError as e:
    #10 9.428     → 1476│             raise EnvCommandError(e, input=input_)
    #10 9.429       1477│
    #10 9.429       1478│         return decode(output)
    #10 9.429       1479│
    #10 9.429       1480│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
    #10 9.429   Failed to install /root/.cache/pypoetry/artifacts/af/19/9f/f71f7f0d313981e3dce1608dc021f6f4a338dd61aa21f8e1bbeb8a1deb/mysqlclient-2.1.1.tar.gz
    #10 9.429
    #10 9.429   at /opt/poetry/venv/lib/python3.10/site-packages/poetry/utils/pip.py:51 in pip_install
    #10 9.431        47│
    #10 9.431        48│     try:
    #10 9.431        49│         return environment.run_pip(*args)
    #10 9.431        50│     except EnvCommandError as e:
    #10 9.432     →  51│         raise PoetryException(f"Failed to install {path.as_posix()}") from e
    #10 9.432        52│
    #10 9.432
    ------
    executor failed running [/bin/sh -c poetry install  # respects]: exit code: 1
    ERROR: Service 'web' failed to build : Build failed

更新

代码语言:javascript
运行
复制
(flask-user-module-py3.10) PS D:\Projects\user-module\deploy> docker-compose -f docker-compose.yml --env-file ./web-variables.env build
mysql uses an image, skipping
Building web
[+] Building 16.3s (10/17)
 => [internal] load build definition from dockerfile                                                                                                                              0.0s
 => => transferring dockerfile: 1.78kB                                                                                                                                            0.0s 
 => [internal] load .dockerignore                                                                                                                                                 0.0s 
 => => transferring context: 2B                                                                                                                                                   0.0s 
 => [internal] load metadata for docker.io/library/python:3.10-slim                                                                                                               1.3s 
 => [internal] load build context                                                                                                                                                 0.0s
 => => transferring context: 598B                                                                                                                                                 0.0s 
 => CACHED [python-base 1/1] FROM docker.io/library/python:3.10-slim@sha256:685b1c2ef40bd3ded77b3abd0965d5c16d19a20469be0ac06a3cf1d33f2e6d41                                      0.0s 
 => CACHED [builder-base 1/5] RUN apt-get update     && apt-get install --no-install-recommends -y         curl         build-essential        default-libmysqlclient-dev         0.0s 
 => CACHED [builder-base 2/5] RUN curl -sSL https://install.python-poetry.org | python                                                                                            0.0s 
 => CACHED [builder-base 3/5] WORKDIR /opt/pysetup                                                                                                                                0.0s 
 => CACHED [builder-base 4/5] COPY ./poetry.lock ./pyproject.toml ./                                                                                                              0.0s 
 => ERROR [builder-base 5/5] RUN poetry install  # respects                                                                                                                      14.8s
#10 3.601   • Installing werkzeug (2.2.2)
#10 5.295   • Installing flask (2.2.2)
#10 5.296   • Installing mysqlclient (2.1.1)
#10 5.297   • Installing pymysql (1.0.2)
#10 10.25   • Installing flask-mysql (1.5.2)
#10 10.25   • Installing flask-mysqldb (1.0.1)
#10 10.25   • Installing flask-paginate (2022.1.8)
#10 14.64
#10 14.64 /opt/pysetup/flask_user_module does not contain any element
------
executor failed running [/bin/sh -c poetry install  # respects]: exit code: 1
ERROR: Service 'web' failed to build : Build failed
EN

回答 1

Stack Overflow用户

发布于 2022-10-18 06:08:50

mysql_config似乎在您的web图像中丢失了。我想你需要把这一行改为:

代码语言:javascript
运行
复制
RUN apt-get update \
    && apt-get install --no-install-recommends -y \
        curl \
        build-essential \
        default-libmysqlclient-dev

如果上面的一个不起作用,请尝试安装python-devpython-MySQLdb

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74106137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档