#python #docker #pip #cron
#python #docker #pip #cron
Вопрос:
Я должен запланировать выполнение скрипта python в контейнере docker. Мой скрипт использует несколько пакетов, которые я должен установить, так что это мой Dockerfile:
FROM python:3.9.0b4-alpine3.12
COPY AzureVM /bin/AzureVM
COPY root /var/spool/cron/crontabs/root
RUN pip install azure-common
RUN pip install azure-mgmt-compute
RUN pip install msrestazure
RUN pip install paramiko
RUN chmod x /bin/AzureVM
CMD crond -l 2 -f
Когда я пытаюсь собрать контейнер, он выдает огромные ошибки для некоторых пакетов (в частности, msrestazure и paramiko). Например:
Step 6/8 : RUN pip install msrestazure
---> Running in f02284bb6aee
Collecting msrestazure
Downloading msrestazure-0.6.4-py2.py3-none-any.whl (40 kB)
Requirement already satisfied: msrest<2.0.0,>=0.6.0 in /usr/local/lib/python3.9/site-packages (from msrestazure) (0.6.19)
Collecting adal<2.0.0,>=0.6.0
Downloading adal-1.2.4-py2.py3-none-any.whl (55 kB)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from msrestazure) (1.15.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from msrest<2.0.0,>=0.6.0->msrestazure) (2020.6.20)
Requirement already satisfied: requests-oauthlib>=0.5.0 in /usr/local/lib/python3.9/site-packages (from msrest<2.0.0,>=0.6.0->msrestazure) (1.3.0)
Requirement already satisfied: requests~=2.16 in /usr/local/lib/python3.9/site-packages (from msrest<2.0.0,>=0.6.0->msrestazure) (2.24.0)
Requirement already satisfied: isodate>=0.6.0 in /usr/local/lib/python3.9/site-packages (from msrest<2.0.0,>=0.6.0->msrestazure) (0.6.0)
Collecting python-dateutil>=2.1.0
Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting PyJWT>=1.0.0
Downloading PyJWT-1.7.1-py2.py3-none-any.whl (18 kB)
Collecting cryptography>=1.1.0
Downloading cryptography-3.1.tar.gz (534 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.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-8e8f308c/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"''
cwd: None
Complete output (37 lines):
Collecting setuptools>=40.6.0
Downloading setuptools-50.3.0-py3-none-any.whl (785 kB)
Collecting wheel
Downloading wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Collecting cffi!=1.11.3,>=1.8
Downloading cffi-1.14.3.tar.gz (470 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5nw42fq5/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5nw42fq5/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-l9k0d28w
cwd: /tmp/pip-install-5nw42fq5/cffi/
Complete output (23 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-5nw42fq5/cffi/setup.py", line 163, in <module>
ask_supports_thread()
File "/tmp/pip-install-5nw42fq5/cffi/setup.py", line 81, in ask_supports_thread
config.try_compile('__thread int some_threadlocal_variable_42;'))
File "/usr/local/lib/python3.9/distutils/command/config.py", line 225, in try_compile
self._compile(body, headers, include_dirs, lang)
File "/usr/local/lib/python3.9/distutils/command/config.py", line 132, in _compile
self.compiler.compile([src], include_dirs=include_dirs)
File "/usr/local/lib/python3.9/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/usr/local/lib/python3.9/distutils/unixccompiler.py", line 117, in _compile
self.spawn(compiler_so cc_args [src, '-o', obj]
File "/usr/local/lib/python3.9/distutils/ccompiler.py", line 910, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/usr/local/lib/python3.9/distutils/spawn.py", line 74, in spawn
proc = subprocess.Popen(cmd, env=env)
File "/usr/local/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gcc'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 20.2.3 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.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-8e8f308c/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
The command '/bin/sh -c pip install msrestazure' returned a non-zero code: 1
Я попытался изменить базовый образ (slim, buster, slim-buster), и все пакеты были установлены, но затем я каждый раз получал следующую ошибку:
Crond not found
Когда я пытаюсь запланировать простой скрипт (без каких-либо странных установок), он работает нормально (только с python: 3.9.0b4-alpine3.12). Я не знаю, что делать, поэтому, пожалуйста, помогите!
Комментарии:
1. Ошибка говорит, что вам необходимо установить
gcc
для компиляции вашего модуля. Вы также не устанавливаете cron в свой dockerfile.
Ответ №1:
Добавьте это перед выполнением pip
команд.
RUN apk add build-base libffi-dev openssl-dev --no-cache
Проверено ниже Dockerfile
. Остальные шаги вы можете добавить соответствующим образом.
FROM python:3.9.0b4-alpine3.12
RUN apk add build-base libffi-dev openssl-dev --no-cache
RUN pip install azure-common
amp;amp; pip install azure-mgmt-compute
amp;amp; pip install msrestazure
amp;amp; pip install paramiko