在docker run上使用--user选项的Docker Entrypoint错误

时间:2018-07-26 14:35:15

标签: python docker docker-entrypoint docker-run

当我只想让我的容器作为非根文件写入时,我发现docker run有这个问题。

当我使用这种命令(入口点被覆盖)时,我没有任何问题:

docker run -u `id -u $USER` --entrypoint  bash -it --rm -v somepath:somepathincontainer IMAGE

工作正常,我可以使用I have no name!用户帐户x)访问该容器

但是,在不像这里这样覆盖入口点的情况下:

docker run -u `id -u $USER` -it --rm -v somepath:somepathincontainer IMAGE

我遇到此错误:

Traceback (most recent call last):
  File "/usr/local/bin/readmapper", line 4, in <module>
__import__('pkg_resources').run_script('MYTOOL==1.0.1', 'MYTOOL')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1504, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.5/dist-packages/MYTOOL-1.0.1-py3.5.egg/EGG-INFO/scripts/MYTOOL", line 5, in <module>
    from MYTOOL import FUNC1, FUNC2, FUNC3
  File "/usr/local/lib/python3.5/dist-packages/MYTOOL-1.0.1-py3.5.egg/MYTOOL/FUNC3.py", line 6, in <module>
    import pandas as pd
  File "/usr/local/lib/python3.5/dist-packages/pandas/__init__.py", line 42, in <module>
    from pandas.core.api import *
  File "/usr/local/lib/python3.5/dist-packages/pandas/core/api.py", line 10, in <module>
    from pandas.core.groupby.groupby import Grouper
  File "/usr/local/lib/python3.5/dist-packages/pandas/core/groupby/__init__.py", line 2, in <module>
    from pandas.core.groupby.groupby import (
  File "/usr/local/lib/python3.5/dist-packages/pandas/core/groupby/groupby.py", line 49, in <module>
    from pandas.core.frame import DataFrame
  File "/usr/local/lib/python3.5/dist-packages/pandas/core/frame.py", line 74, in <module>
    from pandas.core.series import Series
  File "/usr/local/lib/python3.5/dist-packages/pandas/core/series.py", line 80, in <module>
    import pandas.plotting._core as gfx
  File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/__init__.py", line 11, in <module>
    from pandas.plotting._core import boxplot
  File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 45, in <module>
    from pandas.plotting import _converter
  File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_converter.py", line 8, in <module>
    import matplotlib.units as units
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 1133, in <module>
    rcParams = rc_params()
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 967, in rc_params
    fname = matplotlib_fname()
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 796, in matplotlib_fname
    configdir = _get_configdir()
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 649, in _get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 626, in _get_config_or_cache_dir
    return _create_tmp_config_dir()
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 555, in _create_tmp_config_dir
    tempdir = os.path.join(tempdir, 'matplotlib-%s' % getpass.getuser())
  File "/usr/lib/python3.5/getpass.py", line 170, in getuser
    return pwd.getpwuid(os.getuid())[0]
KeyError: 'getpwuid(): uid not found: 1001'

编辑1

I have no name!@c9368637178d:/$ id
uid=1001 gid=0(root) groups=0(root)

请问我更多信息。

1 个答案:

答案 0 :(得分:0)

解决了将此问题添加到DockerFile

RUN useradd MYUSERNAME --uid 1001