惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
小众软件
小众软件
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享

西行妖

T618冷门平板刷机从入门到理赔 12700h es新all in Boom折腾记录 Kde6 Electron程序在wayland模式下无法运行终极解决方案 蜗牛星际NAS再次折腾记录 2023年度总结 CS61B最后的总结:比较排序与基数排序 工程机,我劝你别买 为thinkbook14p G3更换高刷屏幕 专有名词笔记 时间轴 谷歌域名即将被收购,如何薅到最后一波羊毛 人在囧途——记录我的日本之行 记一次衣服被子被偷的离谱经历 关于本站迁移的公告 java的某些常用特性 python3将对象作为线程使用 在Chromebook上使用Windows是什么体验?记录我到目前为止用过的Chromebook Chromebook刷bios解除企业锁折腾记录 Vue3的computed计算属性传参 将操作系统从Windows转向Linux [预告]固态硬盘太贵?试试看自己做一个吧 A卡深度学习服务器折腾&踩坑记 Ai绘画体验——利用校徽生成对应虚拟形象 AutoWhitelist诈尸更新dev&新的未来计划 它很好,但对我来说不够好——关于华硕无双15.6 [推广]蓝易云暑期大采购活动 Potplayer+SVP4插帧看番体验——24帧日漫轻松提升至60帧 AList搭建教程&网盘迁移至AList公告 Autowhitelist介绍&我对mc白名单的研究 还是v2ex大神多,记一次遇到bug被大佬拯救
在Docker容器中运行服务
zsx · 2023-03-25 · via 西行妖

最近正在写的某个容器升级了一下架构,在启动容器时需要同时运行一个frps服务。根据我的习惯,一开始打算使用systemctl添加frps服务,然后enable一下以实现开机自启。但在我实际使用时,发现服务没有跑起来。查了一下日志,发现了这条报错:

ERROR:systemctl: frps.service: Executable path is not absolute, ignoring: ./frps -c /frps.ini ERROR:systemctl: Exec is not an absolute path: ExecStart=./frps -c /frps.ini ERROR:systemctl: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR:systemctl: Found 1 problems in /etc/systemd/system/frps.service ERROR:systemctl: The SystemD commands must always be absolute paths by definition. ERROR:systemctl: Earlier versions of systemctl.py did use a subshell thus using $PATH ERROR:systemctl: however newer versions use execve just like the real SystemD daemon ERROR:systemctl: so that your docker-only service scripts may start to fail suddenly. ERROR:systemctl: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

去官网稍微找了下,发现了这段解释:

This is by design. Docker should be running a process in the foreground in your container and it will be spawned as PID 1 within the container’s pid namespace. Docker is designed for process isolation, not for OS virtualization, so there are no other OS processes and daemons running inside the container (like systemd, cron, syslog, etc), only your entrypoint or command you run. If they included systemd commands, you’d find a lot of things not working since your entrypoint replaces init. Systemd also makes use to cgroups which docker restricts inside of containers since the ability to change cgroups could allow a process to escape the container’s isolation. Without systemd running as init inside your container, there’s no daemon to process your start and stop commands.

大意就是:docker只是提供了进程隔离,不是操作系统的虚拟,所以不能运行systemd。

如果只想同时运行两个服务,应该用什么办法呢?其实很简单:在Dockerfile CMD内运行start.sh,然后再用nohup挂起frps服务就好了: nohup ./frps -c /frps.ini & python3 /main.py 顺利运行frps服务。