当前位置:   article > 正文

docker中无法使用systemctl的问题的解决_systemctl用不了

systemctl用不了

问题

docker里面无法使用systemctl

root@0d6129fc601a:/# systemctl start ndpd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@0d6129fc601a:/# 
  • 1
  • 2
  • 3
  • 4

centos

这个容易解决

admin@test:~$ docker run -itd --name test --privileged=true centos:centos8 /usr/sbin/init
9b3b32475a4e1c94018eb82ca5df37b49c274ca713fca9f8039ac836e5022008
admin@test:~$ 

admin@test:~$ docker exec -it test /bin/bash
[root@9b3b32475a4e /]# 
[root@9b3b32475a4e /]# 
[root@9b3b32475a4e /]# systemctl start lldpd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Ubuntu(18/20)

在网上搜了很多方法,都不行

admin@test:~$ docker run -itd --privileged --name test ubuntu:18.04 /usr/sbin/init
0fd49180f44beb1246760dd213a9f18d0eff5b3abb5a27aea1385f0583777981
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/usr/sbin/init\": stat /usr/sbin/init: no such file or directory": unknown.`
  • 1
  • 2
  • 3
admin@test:~$ docker run -itd --privileged --name test ubuntu:18.04 /sbin/init
a2b206249e1b3febfe9ca310386140513b401614da634b131391ade75408ed0b
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/sbin/init\": stat /sbin/init: no such file or directory": unknown.
admin@test:~$ 
  • 1
  • 2
  • 3
  • 4

最后在这里找到了解决方法
这样来看,跟当初创建Ubuntu docker镜像的时候有关,需要使用特殊的镜像

admin@test:~$ docker run -d --name linuxamination --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro jrei/systemd-ubuntu:20.04
Unable to find image 'jrei/systemd-ubuntu:20.04' locally
20.04: Pulling from jrei/systemd-ubuntu
16ec32c2132b: Pull complete 
6daf711395b1: Pull complete 
6c1d92d48249: Pull complete 
4b5388c246dd: Pull complete 
78823b6538a5: Pull complete 
Digest: sha256:ba4b34db6b88a45b64c1f3dc45e1d519550c628ebc10c53420f8930926eda802
Status: Downloaded newer image for jrei/systemd-ubuntu:20.04
4abb2206952bc62e56d051a1d284daf9dff04ce10088dd48d71023ad35f738ec
admin@test:~$ 
admin@test:~$ docker exec -it linuxamination bash
root@4abb2206952b:/# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.1  0.0  19948  9492 ?        Ss   00:52   0:00 /lib/systemd/systemd
root          21  0.2  0.0  26636 12048 ?        S<s  00:52   0:00 /lib/systemd/systemd-journald
root          23  0.0  0.0   4244  3376 pts/0    Ss   00:52   0:00 bash
root          30  0.0  0.0   5900  2848 pts/0    R+   00:52   0:00 ps aux
root@4abb2206952b:/# 
root@4abb2206952b:/# cat /etc/issue
Ubuntu 20.04.2 LTS \n \l

root@4abb2206952b:/# 
root@4abb2206952b:/# apt update -y    
root@4abb2206952b:/# apt install lldp -y

root@4abb2206952b:/# systemctl start lldpd
root@4abb2206952b:/# 
root@4abb2206952b:/# systemctl status lldpd     
* lldpd.service - LLDP daemon
     Loaded: loaded (/lib/systemd/system/lldpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-08-25 00:58:27 UTC; 4s ago
       Docs: man:lldpd(8)
   Main PID: 876 (lldpd)
      Tasks: 2 (limit: 154062)
     Memory: 1.8M
     CGroup: /system.slice/containerd.service/system.slice/lldpd.service
             |-876 lldpd: monitor.
             `-878 lldpd: no neighbor.

Aug 25 00:58:27 4abb2206952b systemd[1]: Started LLDP daemon.
Aug 25 00:58:27 4abb2206952b lldpd[878]: /etc/localtime copied to chroot
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol LLDP enabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol CDPv1 disabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol CDPv2 disabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol SONMP disabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol EDP disabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: protocol FDP disabled
Aug 25 00:58:27 4abb2206952b lldpd[878]: libevent 2.1.11-stable initialized with epoll method
Aug 25 00:58:27 4abb2206952b lldpcli[877]: lldpd should resume operations
root@4abb2206952b:/# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

贴出docker镜像所在地址,Ubuntu的16/18/20都有
https://hub.docker.com/r/jrei/systemd-ubuntu

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/573265
推荐阅读
相关标签
  

闽ICP备14008679号