Home > OS >  Python docker image build fails due to gcc error
Python docker image build fails due to gcc error

Time:05-22

I am studying Nornir and want to containerize my application, here is the Dockerfile content:

FROM alpine

RUN apk update && apk upgrade 
RUN apk add gcc && apk add py3-pip && apk add libevent-dev
RUN apk add python3-dev && pip3 install nornir 

When I build the container with the command:

docker build --network=host .

I get the following errors:

somaiia@main-srv:~/core/nornir$ docker build --no-cache --network=host .
Sending build context to Docker daemon  10.24kB
Step 1/4 : FROM alpine
...
Step 4/4 : RUN apk add python3-dev && pip3 install nornir
 ---> Running in 025aee6693e4
(1/1) Installing python3-dev (3.9.7-r4)
Executing busybox-1.34.1-r5.trigger
OK: 229 MiB in 66 packages
Collecting nornir
  Downloading nornir-3.3.0-py3-none-any.whl (30 kB)
Collecting typing_extensions<5.0,>=4.1
  Downloading typing_extensions-4.2.0-py3-none-any.whl (24 kB)
Collecting importlib-metadata<5,>=4
  Downloading importlib_metadata-4.11.4-py3-none-any.whl (18 kB)
Collecting ruamel.yaml>=0.17
  Downloading ruamel.yaml-0.17.21-py3-none-any.whl (109 kB)
Collecting mypy_extensions<0.5.0,>=0.4.1
  Downloading mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting zipp>=0.5
  Downloading zipp-3.8.0-py3-none-any.whl (5.4 kB)
Collecting ruamel.yaml.clib>=0.2.6
  Downloading ruamel.yaml.clib-0.2.6.tar.gz (180 kB)
    **ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vs5bwupe/ruamel-yaml-clib_e6dc2477a7f349c6866be26f31b40c2e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vs5bwupe/ruamel-yaml-clib_e6dc2477a7f349c6866be26f31b40c2e/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-jh_alwhp
         cwd: /tmp/pip-install-vs5bwupe/ruamel-yaml-clib_e6dc2477a7f349c6866be26f31b40c2e/
    Complete output (7 lines):
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared
    collect2: error: ld returned 1 exit status
    sys.argv ['/tmp/pip-install-vs5bwupe/ruamel-yaml-clib_e6dc2477a7f349c6866be26f31b40c2e/setup.py', 'egg_info', '--egg-base', '/tmp/pip-pip-egg-info-jh_alwhp']
    test compiling /tmp/tmp_ruamel_zq9s1x2j/test_ruamel_yaml.c -> test_ruamel_yaml link error /tmp/tmp_ruamel_zq9s1x2j/test_ruamel_yaml.c
    Exception: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/8b/25/08e5ad2431a028d0723ca5540b3af6a32f58f25e83c6dda4d0fcef7288a3/ruamel.yaml.clib-0.2.6.tar.gz#sha256=4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd (from https://pypi.org/simple/ruamel-yaml-clib/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Collecting ruamel.yaml>=0.17
  Downloading ruamel.yaml-0.17.20-py3-none-any.whl (109 kB)
  Downloading ruamel.yaml-0.17.19-py3-none-any.whl (109 kB)
  Downloading ruamel.yaml-0.17.18-py3-none-any.whl (109 kB)
  Downloading ruamel.yaml-0.17.17-py3-none-any.whl (109 kB)
Collecting ruamel.yaml.clib>=0.1.2
  Downloading ruamel.yaml.clib-0.2.2.tar.gz (179 kB)
Using legacy 'setup.py install' for ruamel.yaml.clib, since package 'wheel' is not installed.
Installing collected packages: zipp, ruamel.yaml.clib, typing-extensions, ruamel.yaml, mypy-extensions, importlib-metadata, nornir
    Running setup.py install for ruamel.yaml.clib: started
    Running setup.py install for ruamel.yaml.clib: finished with status 'done'
Successfully installed importlib-metadata-4.11.4 mypy-extensions-0.4.3 nornir-3.3.0 ruamel.yaml-0.17.17 ruamel.yaml.clib-0.2.2 typing-extensions-4.2.0 zipp-3.8.0**

I am unable to build Nornir and can't proceed with the next steps as a result, what can I do?

CodePudding user response:

In the logs the error originates from this

Collecting ruamel.yaml.clib>=0.2.6
  Downloading ruamel.yaml.clib-0.2.6.tar.gz (180 kB)
    **ERROR: Command errored out with exit status 1:

But following the logs we this

Collecting ruamel.yaml.clib>=0.1.2
   Downloading ruamel.yaml.clib-0.2.2.tar.gz (179 kB)

Basically the first dependeny requirement demanded the ruamel.yaml.clib version to be greater or equal to 0.2.6, but it failed.

In the next try it tried for a version greater or equal to 0.1.2.

In the final logs we see

Successfully installed ... nornir-3.3.0 ruamel.yaml.clib-0.2.2 ...**

Meaning it successfully installed an older version of ruamel.yaml.clib library and finally installed the nornir library as well

  • Related