内容目录
起因
游戏合服,需要做一个环境的容器镜像推到镜像仓库,原来是台老物理机,centos6.5 python3.8.4
最终方案一般在最下面 不想看折腾历程 拉到底看结果
pip --version
pip 21.0.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)
镜像from选择
最开始dockerfile选择FROM python:3.9-alpine
但是这个基础镜像
pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install pymysql_utils -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
第二步必报错
# pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (23.3.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
/ # pip install pymysql_utils -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting pymysql_utils
Using cached https://mirrors.cloud.tencent.com/pypi/packages/cc/48/88c2e1f8cee06a486d5abe8230b627d224bf7ab12556e083e159432efa4c/pymysql_utils-2.1.5-py3-none-any.whl (26 kB)
Collecting mysqlclient>=1.3.14 (from pymysql_utils)
Using cached https://mirrors.cloud.tencent.com/pypi/packages/de/9c/b176826e8994551ce826404dab97e305a4bb76c8b0a4e016fabda2901c71/mysqlclient-2.2.0.tar.gz (89 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [22 lines of output]
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
Trying pkg-config --exists mariadb
Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "/tmp/pip-build-env-fl0gq7z4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "/tmp/pip-build-env-fl0gq7z4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-fl0gq7z4/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in run_setup
exec(code, locals())
File "<string>", line 154, in <module>
File "<string>", line 48, in get_config_posix
File "<string>", line 27, in find_package_name
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
最后选择FROM python:3.12.0 这个的基础镜像是debian12进行环境安装测试 最后再写dockerfile
因为在国内经常超时会报
root@aab0e3284ca9:/# pip3 install pymysql_utils
Collecting pymysql_utils
Downloading pymysql_utils-2.1.5-py3-none-any.whl (26 kB)
Collecting mysqlclient>=1.3.14 (from pymysql_utils)
Downloading mysqlclient-2.2.0.tar.gz (89 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.5/89.5 kB 480.3 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install backend dependencies did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Collecting wheel
Obtaining dependency information for wheel from https://files.pythonhosted.org/packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c722a0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c71dc0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c73380>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c72450>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c71d00>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/fa/7f/4c07234086edbce4a0a446209dc0cb08a19bb206a3ea53b2f56a403f983b/wheel-0.41.3-py3-none-any.whl.metadata (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1267c72870>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))
[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install backend dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip
最后
pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install pymysql_utils -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
解决
基础镜像python:3.12.0 安装mysql客户端
原来是没有的
root@aab0e3284ca9:/# apt-get install -y mysql
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package mysql
root@aab0e3284ca9:/# apt-get list
E: Invalid operation list
下载安装mysql apt 官方库
wget https://repo.mysql.com//mysql-apt-config_0.8.28-1_all.deb
dpkg -i mysql-apt-config_0.8.28-1_all.deb
提示少了lsb-release
root@aab0e3284ca9:/# dpkg -i mysql-apt-config_0.8.28-1_all.deb
dpkg: regarding mysql-apt-config_0.8.28-1_all.deb containing mysql-apt-config, pre-dependency problem:
mysql-apt-config pre-depends on lsb-release
lsb-release is not installed.
dpkg: error processing archive mysql-apt-config_0.8.28-1_all.deb (--install):
pre-dependency problem - not installing mysql-apt-config
Errors were encountered while processing:
mysql-apt-config_0.8.28-1_all.deb
千辛万苦网上找到
wget https://mirrors.aliyun.com/debian/pool/main/l/lsb/lsb-release_11.1.0_all.deb
dpkg -i lsb-release_11.1.0_all.deb
提示
root@aab0e3284ca9:/# wget https://mirrors.aliyun.com/debian/pool/main/l/lsb/lsb-release_11.1.0_all.deb
--2023-11-20 07:40:43-- https://mirrors.aliyun.com/debian/pool/main/l/lsb/lsb-release_11.1.0_all.deb
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 47.118.227.104, 47.118.227.107, 47.118.227.106, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|47.118.227.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27884 (27K) [application/vnd.debian.binary-package]
Saving to: ‘lsb-release_11.1.0_all.deb’
lsb-release_11.1.0_all.deb 100%[==========================================================================================================================================================>] 27.23K --.-KB/s in 0.03s
2023-11-20 07:40:43 (1.00 MB/s) - ‘lsb-release_11.1.0_all.deb’ saved [27884/27884]
root@aab0e3284ca9:/# ls
bin boot dev etc home lib lib32 lib64 libx32 lsb-release_11.1.0_all.deb media mnt mysql-apt-config_0.8.28-1_all.deb opt proc root run sbin srv sys tmp usr var wget-log
root@aab0e3284ca9:/# dpkg -i lsb-release_11.1.0_all.deb
Selecting previously unselected package lsb-release.
(Reading database ... 23974 files and directories currently installed.)
Preparing to unpack lsb-release_11.1.0_all.deb ...
Unpacking lsb-release (11.1.0) ...
dpkg: dependency problems prevent configuration of lsb-release:
lsb-release depends on distro-info-data; however:
Package distro-info-data is not installed.
dpkg: error processing package lsb-release (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
lsb-release
提示缺少distro-info-data 马德套娃依赖
https://mirrors.aliyun.com/debian/pool/main/d/distro-info-data/distro-info-data_0.58+deb12u1_all.deb
dpkg -i distro-info-data_0.58+deb12u1_all.deb
然后依次安装lsb-release mysql-apt-config_0.8.28-1_all.deb
然后apt-get update
root@aab0e3284ca9:/# apt-get update
Get:1 http://repo.mysql.com/apt/debian bookworm InRelease [17.9 kB]
Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:3 http://repo.mysql.com/apt/debian bookworm/mysql-8.0 Sources [948 B]
Get:4 http://repo.mysql.com/apt/debian bookworm/mysql-tools amd64 Packages [3801 B]
Get:5 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:6 http://repo.mysql.com/apt/debian bookworm/mysql-8.0 amd64 Packages [12.6 kB]
Get:7 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8780 kB]
Get:9 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [6668 B]
Get:10 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [102 kB]
Fetched 9175 kB in 14s (643 kB/s)
Reading package lists... Done
一键命令整理
https://mirrors.aliyun.com/debian/pool/main/d/distro-info-data/distro-info-data_0.58+deb12u1_all.deb
dpkg -i distro-info-data_0.58+deb12u1_all.deb
wget https://mirrors.aliyun.com/debian/pool/main/l/lsb/lsb-release_11.1.0_all.deb
dpkg -i lsb-release_11.1.0_all.deb
wget https://repo.mysql.com//mysql-apt-config_0.8.28-1_all.deb
#这个需要交互操作好烦
dpkg -i mysql-apt-config_0.8.28-1_all.deb
apt-get update
apt-get install mysql-community-client -y
因为需要交互操作,放弃
最后使用mariadb client反正一样支持mysql命令
dockerfile
FROM python:3.12.0
#作者
MAINTAINER qiuf<qiufuzi@gmail.com>
#RUN apt-get update
RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash
RUN apt-get install mariadb-client -y
#国内超时加速使用 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 国外的话可以不用
RUN pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN pip install pymysql_utils -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
CMD ["python3"]
因为镜像推送k8s部署,需要有个端口做健康检查加个nginx
FROM python:3.12.0
#作者
MAINTAINER qiuf<qiufuzi@gmail.com>
#RUN apt-get update
RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash
RUN apt-get install mariadb-client nginx -y
#国内超时加速使用 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 国外的话可以不用
RUN pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN pip install pymysql_utils -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
EXPOSE 80/tcp
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
近期评论