How can I use systemctl from within a docker container (run on ubuntu 20.04, with ubuntu 18.04 base)
参考文章: https://notesail.com/posts/docker-systemctl.html
vscode + docker 构建远程开发环境: https://zhuanlan.zhihu.com/p/80099904
How can I use systemctl from within a docker container (run on ubuntu 20.04, with ubuntu 18.04 base)
Ask Question
Asked yesterday
Active yesterday
Viewed 21 times
0
I'm trying to start a docker container with systemd as the init process so I can run multiple services from that container, and I get the following weird error:
Systemd is listed as PID 1 when I run top, but none of the services i've enabled through systemctl are running, and trying to systemctl status them gives me system has not been booted with systemd as init process (PID 1)
Here's my dockerfile:
FROM ubuntu:20.04
ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/# deb/deb/g' /etc/apt/sources.list
RUN apt-get update
&& apt-get install -y systemd systemd-sysv
&& apt-get clean
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN cd /lib/systemd/system/sysinit.target.wants/
&& ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1
RUN rm -f /lib/systemd/system/multi-user.target.wants/*
/etc/systemd/system/.wants/
/lib/systemd/system/local-fs.target.wants/*
/lib/systemd/system/sockets.target.wants/udev
/lib/systemd/system/sockets.target.wants/initctl
/lib/systemd/system/basic.target.wants/*
/lib/systemd/system/anaconda.target.wants/*
/lib/systemd/system/plymouth*
/lib/systemd/system/systemd-update-utmp*
...assorted aptget installs...
ENV LOCAL="yes"
...assorted utils scripts...
RUN useradd --create-home fractal
&& usermod -aG sudo fractal \
&& echo 'fractal:password1234567.' | chpasswd
...assorted utils scripts...
ADD bootstrap.sh /home/fractal
ADD entry.sh /home/fractal
ADD fractal-input.rules home/fractal
RUN chmod +x /home/fractal/bootstrap.sh
&& chown -v -R fractal:fractal /home/fractal
RUN chown root:root /run/user
RUN chmod +x /home/fractal/entry.sh
...adding assorted services...
VOLUME [ "/sys/fs/cgroup" ]
RUN systemctl set-default multi-user.target
ENV init /lib/systemd/systemd
....assorted services enabled....
CMD ["/lib/systemd/systemd"]
18.04 20.04 docker
share improve this question
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2018-08-30 deepin linux手工更新系统