【问题标题】:Unable to update python from 3.5.3 to 3.8.5 on docker container无法在 docker 容器上将 python 从 3.5.3 更新到 3.8.5
【发布时间】:2021-05-17 01:13:01
【问题描述】:

我正在尝试更新在 docker 容器中运行的 python 版本,但即使我尝试使用 apt-get updateapt update 更新软件包,然后运行 ​​apt-get install python3.8apt install python3.8 我得到以下信息错误:

apt install python3.8
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.8
E: Couldn't find any package by glob 'python3.8'
E: Couldn't find any package by regex 'python3.8'

我已经尝试过这个链接的答案:How to Install python3.8 on debian 10?

更多信息:

我的 docker-compose.yml

version: "3.3"
services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_DB: ${DB_DATABASE}
    volumes:
      - ./pgdata:/var/lib/postgres/data
    ports:
      - "${DB_PORT}:${DB_PORT}"
  web:
    image: node:12
    restart: always
    depends_on:
      - db
    ports:
      - 3000:3000
    volumes:
      - ./:/usr/app
    working_dir: /usr/app
    command: bash -c "apt-get update && apt-get install -y python3 wget && wget https://bootstrap.pypa.io/pip/3.5/get-pip.py && python3 get-pip.py && pip install opencv-contrib-python==4.1.2.30 && pip3 install numpy && pip3 install imutils && pip3 install pickle-mixin && pip3 install argparse && pip3 install requests && yarn && rm -rf get-pip.py && yarn start"
    environment:
      IMAGE_DIR_NAME: ${my_path}
      PYTHON_PATH: ${my_path}
      SCRYFALL_SCRIPT: ${my_path}
      DB_HOST: db
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"

我该如何解决这个问题?

【问题讨论】:

  • 根据Docker Hubnode:12 基于 Stretch(即 Debian 9)。从某些 PPA 等安装 Python 3.8 可能会更好。
  • 您最好将其重构为单独的 Dockerfile,这样每次启动容器时都不必重复冗长的command:。尚不清楚为什么您需要在基于 node 的容器中使用特定的 Python 版本;你可以使用一个单独的容器,内置在 Dockerfile FROM python:3.8 中,运行 Python 组件吗?

标签: python node.js python-3.x docker docker-compose


【解决方案1】:

我特别建议您使用多级示例 alpine 编译图像,该示例将变得更小,甚至使用带有 python3.8 的 distroless 并且 node12 是更小更安全的容器!但如果您想要一个更简单的解决方案,可以使用这些源代码完美解决您的问题

这里是python和节点图像源代码 https://github.com/nikolaik/docker-python-nodejs

来自 docker hub 镜像

nikolaik/python-nodejs:python3.8-nodejs12-alpine

这里是 distroless 图像

https://github.com/GoogleContainerTools/distroless

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多