![无法在docker容器中启动nginx服务(Oracle linux 7)](https://linux22.com/image/758316/%E6%97%A0%E6%B3%95%E5%9C%A8docker%E5%AE%B9%E5%99%A8%E4%B8%AD%E5%90%AF%E5%8A%A8nginx%E6%9C%8D%E5%8A%A1%EF%BC%88Oracle%20linux%207%EF%BC%89.png)
我在 Oracle Linux 7 docker 镜像上安装了 nginx(rh-nginx116-nginx)。启动容器后,在启动 nginx 服务时出现以下错误:-
[root@7b5b3ae7d392 /]# systemctl status rh-nginx116-nginx
● rh-nginx116-nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/rh-nginx116-nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: timeout) since Sun 2020-10-04 13:19:09 UTC; 11min ago
Process: 264 ExecStart=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 258 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 251 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /usr/bin/scl_enabled rh-nginx116 (code=exited, status=0/SUCCESS)
Process: 250 ExecStartPre=/usr/bin/rm -f /var/opt/rh/rh-nginx116/run/nginx/nginx.pid (code=exited, status=0/SUCCESS)
CGroup: /docker/7b5b3ae7d3922947203ceb8164bd1746c707b0851deb7283cf84f7642564eb54/system.slice/rh-nginx116-nginx.service
├─270 nginx: master process /opt/rh/rh-nginx116/root/usr/sbin/nginx
├─271 nginx: worker process
└─272 nginx: worker process
Oct 04 13:17:39 7b5b3ae7d392 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 04 13:17:39 7b5b3ae7d392 nginx-scl-helper[258]: nginx: the configuration file /etc/opt/rh/rh-nginx1... ok
Oct 04 13:17:39 7b5b3ae7d392 nginx-scl-helper[258]: nginx: configuration file /etc/opt/rh/rh-nginx116/n...ful
Oct 04 13:17:39 7b5b3ae7d392 systemd[1]: Refusing to accept PID outside of service control group, acqu....pid
Oct 04 13:17:39 7b5b3ae7d392 systemd[1]: Refusing to accept PID outside of service control group, acqu....pid
Oct 04 13:19:09 7b5b3ae7d392 systemd[1]: rh-nginx116-nginx.service start operation timed out. Terminating.
Oct 04 13:19:09 7b5b3ae7d392 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Oct 04 13:19:09 7b5b3ae7d392 systemd[1]: Unit rh-nginx116-nginx.service entered failed state.
Oct 04 13:19:09 7b5b3ae7d392 systemd[1]: rh-nginx116-nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
Nginx Systemd 单元文件:
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/opt/rh/rh-nginx116/run/nginx/nginx.pid
EnvironmentFile=/opt/rh/rh-nginx116/service-environment
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /var/opt/rh/rh-nginx116/run/nginx/nginx.pid
ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /usr/bin/scl_enabled rh-nginx116
ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx -t
ExecStart=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
请帮助我。
答案1
我可以在您的日志文件中看到:Refusing to accept PID outside of service control group, acqu....pid
检查一下关联. 如上所述,systemd 现在在允许服务启动之前强制检查服务单元中定义的 PID。
您的 nginx 服务单元可能与您的 systemd 版本不兼容。我建议您检查一下。