离线制作docker+python镜像
首先,我们需要从Docker官方网站下载Docker安装包。找到适合您操作系统的版本,并下载安装包。在已有的python环境下执行。一、离线Docker安装步骤。外网下载Docker安装包。二、制作python镜像。:编写dockerfile。配置加速源(仅限外网)修改带file的依赖。:获取镜像至内网环境。
一、离线Docker安装步骤
步骤一:
外网下载Docker安装包
首先,我们需要从Docker官方网站下载Docker安装包。找到适合您操作系统的版本,并下载安装包。例如:http://mirrors.sustech.edu.cn/docker-ce/linux/static/stable/x86_64/?C=S&O=D
步骤二:
解压tgz包(完成后是一个docker文件夹):
tar -zxvf docker-23.0.1.tgz
步骤三:
将docker目录拷贝到/user/bin下(会提示是否覆盖/usr/bin/runc,覆盖即可):
cp docker/* /usr/bin/
步骤四:
系统注册docker.service服务,对文件进行编辑:
vi /etc/systemd/system/docker.service
添加以下内容:
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s[Install]
WantedBy=multi-user.target
步骤五:
docker.service文件添加可执行权限:
chmod +x /etc/systemd/system/docker.service
步骤六(可选):
配置加速源(仅限外网)
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"]
}
步骤七:
重新加载配置文件:
systemctl daemon-reload
步骤八:
启动docker服务:
systemctl start docker
二、制作python镜像
步骤一:
拉取基础镜像:
docker pull python: 3.8-slim
步骤二:
获取requirements.txt文件:
在已有的python环境下执行
pip freeze > requirements.txt
获取如下,例
amqp @ file:///tmp/amqp-2.6.1-py2.py3-none-any.whl#sha256=aa7f313fb887c91f15474c1229907a04dac0b8135822d6603437803424c0aa59
APScheduler==3.9.1
asgiref==3.7.2
async-timeout @ file:///tmp/async_timeout-4.0.3-py3-none-any.whl#sha256=7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028
attrs==23.1.0
autobahn==23.1.2
Automat==22.10.0
backcall==0.2.0
backports.zoneinfo==0.2.1
bcrypt==3.2.2
beautifulsoup4==4.10.0
billiard @ file:///tmp/billiard-3.6.0.0.tar.gz#sha256=756bf323f250db8bf88462cd042c992ba60d8f5e07fc5636c24ba7d6f4261d84
celery @ file:///tmp/celery-4.3.0-py2.py3-none-any.whl#sha256=528e56767ae7e43a16cfef24ee1062491f5754368d38fcfffa861cdb9ef219be
certifi==2021.10.8
cffi==1.15.0
channels==3.0.5
charset-normalizer==2.0.10
constantly==15.1.0
cryptography==41.0.3
daphne==3.0.2
decorator==5.1.1
Deprecated @ file:///tmp/Deprecated-1.2.14-py2.py3-none-any.whl#sha256=6fac8b097794a90302bdbb17b9b815e732d3c4720583ff1b198499d78470466c
Django==3.2.9
django-apscheduler==0.6.2
django-cors-headers==3.11.0
docx==0.2.4
et-xmlfile==1.1.0
hyperlink==21.0.0
idna==3.3
importlib-metadata==4.12.0
incremental==22.10.0
ipython==7.34.0
jedi==0.18.1
jenkins==1.0.2
Jinja2==3.1.1
kombu @ file:///tmp/kombu-4.6.11-py2.py3-none-any.whl#sha256=be48cdffb54a2194d93ad6533d73f69408486483d189fe9f5990ee24255b0e0a
ldap3==2.9.1
lxml==4.9.3
MarkupSafe==2.1.1
matplotlib-inline==0.1.3
multi-key-dict==2.0.3
openpyxl==3.0.9
packaging @ file:///tmp/packaging-23.1-py3-none-any.whl#sha256=994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61
paramiko==2.10.4
parso==0.8.3
pbr==5.8.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
prettytable==3.2.0
prompt-toolkit==3.0.30
ptyprocess==0.7.0
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pyecharts==1.9.1
Pygments==2.12.0
PyMySQL==1.0.2
PyNaCl==1.5.0
pyOpenSSL==23.2.0
python-dateutil==2.8.2
python-gitlab @ file:///tmp/python_gitlab-3.8.1-py3-none-any.whl#sha256=6d10de90f4fcb95ea92e301528d2442ac5094da9b7137fa1294614369679e791
python-jenkins==1.7.0
python-sonarqube-api @ file:///python_sonarqube_api-2.0.4-py3-none-any.whl#sha256=ebf545290a647b16c8b9cf1b651ae75e5c736d37ed1adc4c69695ab5e694a3da
pytz==2021.3
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0.1
redis @ file:///tmp/redis-4.3.0-py3-none-any.whl#sha256=0b1cc61af1389c6cd27a428a5425d81fbe11961bc2a4317b9c94909aed91b501
requests==2.27.1
requests-toolbelt @ file:///tmp/requests_toolbelt-0.10.1-py2.py3-none-any.whl#sha256=18565aa58116d9951ac39baa288d3adb5b3ff975c4f25eee78555d89e8f247f7
scp==0.14.4
service-identity==21.1.0
simplejson==3.17.6
six==1.16.0
some-package==0.1
soupsieve==2.3.1
sqlparse==0.4.2
traitlets==5.3.0
Twisted==23.8.0
txaio==23.1.1
typing_extensions @ file:///tmp/typing_extensions-4.7.1-py3-none-any.whl#sha256=440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36
tzdata==2022.1
tzlocal==4.1
unicode==2.9
urllib3==1.26.8
vine @ file:///tmp/vine-1.3.0-py2.py3-none-any.whl#sha256=ea4947cc56d1fd6f2095c8d543ee25dad966f78692528e68b4fada11ba3f98af
wcwidth==0.2.5
wfastcgi==3.0.0
wrapt @ file:///tmp/wrapt-1.12.1.tar.gz#sha256=b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7
xlrd==1.2.0
xlwt==1.3.0
XMind==1.2.0
zipp==3.8.1
zope.interface==6.0
修改带file的依赖
修改为
amqp==2.6.1
以此类推,
步骤三:编写dockerfile
FROM python:3.8-slim
COPY requirements.txt /tmp/
COPY *whl /tmp/
RUN pip install --no-index --find-links=/tmp/ -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
步骤四:构建镜像
docker build -t python:3.8-slim-test .
步骤五:保存镜像
docker save -o python.tar python:3.8-slim-test
步骤六:获取镜像至内网环境
docker load -i python.tar
更多推荐
所有评论(0)