我启动了一个 CentOS 8 虚拟机来测试这一点,运行podman
您帖子中的命令确实导致失败。今天早上我花了一点时间试图弄清楚发生了什么。
查看 的输出podman run
,我可以看到以下错误:
[root@localhost data]# podman run --name tiles -v /tmp/data:/data -p 8080:80 docker.io/klokantech/openmaptiles-server
[...]
2019-11-05 12:29:26,812 INFO exited: wizard (exit status 1; not expected)
如果我podman exec
进入容器,我可以手动运行wizard
命令并查看更详细的日志。首先,我们需要弄清楚wizard
命令所在的位置。由于容器supervisord
用作进程监督器,这意味着我们可能需要查看/etc/supervisor
详细信息:
[root@localhost ~]# podman exec -it tiles bash
root@de362646e453:/etc/supervisor# cd /etc/supervisor/
root@de362646e453:/etc/supervisor# ls
conf.d supervisord.conf
root@de362646e453:/etc/supervisor# cd conf.d/
root@de362646e453:/etc/supervisor/conf.d# ls
openmaptiles.conf
root@de362646e453:/etc/supervisor/conf.d# cat openmaptiles.conf
[program:wizard]
command=/bin/bash -c "cd /usr/local/src && node wizard"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
autostart=true
autorestart=false
startsecs=0
关键信息是文件中的command
行openmaptiles.conf
。让我们尝试手动运行相同的命令:
root@de362646e453:/# cd /usr/local/src/
root@de362646e453:/usr/local/src# node wizard
Starting OpenMapTiles Map Server (action: run)
fs.js:961
return binding.readdir(pathModule._makeLong(path), options.encoding);
^
Error: EACCES: permission denied, scandir '/data'
at Error (native)
at Object.fs.readdirSync (fs.js:961:18)
at Wizard.init (/usr/local/src/wizard/src/main.js:928:19)
at new Wizard (/usr/local/src/wizard/src/main.js:119:8)
at Object.<anonymous> (/usr/local/src/wizard/src/main.js:1270:1)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
我们在/data
目录上收到“权限被拒绝”错误。权限看起来不错:
root@de362646e453:/# ls -ld /data
drwxr-xr-x. 2 root root 6 Nov 5 12:08 /data
但我们无法访问它:
root@de362646e453:/# cd /data
root@de362646e453:/data# ls
ls: cannot open directory '.': Permission denied
如果文件权限看起来不错,但您仍然无法访问某些内容,这通常意味着是时候查看您的 selinux 配置了。RHEL(和 CentOS)都默认启用 selinux。这将阻止容器访问文件系统中没有被明确授予访问权限的部分。
首先,在主机上,让我们验证是否selinux
在enforcing
模式下运行:
[root@localhost ~]# getenforce
Enforcing
它是(如预期的那样)。让我们将其置于许可模式,看看是否能解决我们的问题:
[root@localhost ~]# setenforce 0
现在在容器中,让我们/data
再次尝试访问该目录:
[root@localhost ~]# podman exec -it tiles bash
root@de362646e453:/# ls /data
root@de362646e453:/#
伟大的!没有更多的错误。让我们尝试重新启动容器:
[root@localhost data]# podman run --name tiles -v $(pwd):/data -p 8080:80 docker.io/klokantech/openmaptiles-server
/usr/lib/python2.7/dist-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
2019-11-05 12:37:18,493 CRIT Supervisor running as root (no user in config file)
2019-11-05 12:37:18,493 INFO Included extra file "/etc/supervisor/conf.d/openmaptiles.conf" during parsing
2019-11-05 12:37:18,498 INFO Creating socket tcp://localhost:8081
2019-11-05 12:37:18,500 INFO Closing socket tcp://localhost:8081
2019-11-05 12:37:18,510 INFO RPC interface 'supervisor' initialized
2019-11-05 12:37:18,511 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2019-11-05 12:37:18,511 INFO supervisord started with pid 1
2019-11-05 12:37:19,514 INFO spawned: 'wizard' with pid 8
2019-11-05 12:37:19,516 INFO spawned: 'xvfb' with pid 9
Starting OpenMapTiles Map Server (action: run)
2019-11-05 12:37:19,954 INFO success: wizard entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-11-05 12:37:19,954 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
Config file not found!
Starting installation...
Installation wizard started at http://:::80/
List of available downloads ready.
这看起来像是一个成功的启动,事实上,我现在可以访问主机端口上的切片服务器8080
。
现在我们要做一个决定:
- 我们可以永久禁用 selinux,或者
- 我们可以更新我们的 selinux 配置以允许当前被拒绝的访问。
我通常会建议(2),但看起来 CentOS 8 中的默认 selinux 策略有一些愚蠢的默认设置,使进程更难(识别问题的审计日志消息被禁用),所以让我们使用(1):
编辑/etc/selinux/config
.
更改SELINUX=enforcing
为SELINUX=permissive
(允许访问但 selinux 仍处于活动状态并将记录策略违规)或SELINUX=disabled
.
重新启动以确保更改按预期进行。
有了这个改变,我的 CentOS 8 虚拟机现在可以毫无问题地运行切片服务器。