zoukankan      html  css  js  c++  java
  • docker容器内使用systemctl报错

    问题:

    在docker容器中使用systemctl命令报错

    [root@707a5892dae2 /]# systemctl start nginx
    System has not been booted with systemd as init system (PID 1). Can't operate.
    Failed to connect to bus: Host is down
    

    原因:

    默认情况下,在第一步执行的是/bin/bash,而docker中的bug,无法使用systemctl
    所以使用/usr/sbin/init同时添加--privileged=true参数就能够使用systemctl了,但覆盖了默认的/bin/bash,因此我们想进入容器就不能使用docker attach了;而只能使用docker exec -it <dockername> /bin/bash

    解决办法:

    运行容器时添加--privileged=true,修改/bin/bash/usr/sbin/init;

    [root@919 ~]# docker run -itd --name nginxv2 --privileged=true centos /usr/sbin/init 
    # --privileged: 指定容器是否是特权容器。
    

    验证:

    [root@919 ~]# docker exec -it nginxv2 /bin/bash
    [root@491ab139e4fd /]# systemctl start nginx
    [root@491ab139e4fd /]# ps -ef |grep nginx
    root         187       1  0 02:32 ?        00:00:00 nginx: master process /usr/sbin/nginx
    nginx        188     187  0 02:32 ?        00:00:00 nginx: worker process
    
    作者:ccku
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有问题或建议,请多多赐教,非常感谢。
  • 相关阅读:
    第13章 使用ADO.NET访问数据库
    第11章 连接查询和分组查询
    第10章 模糊查询和聚合函数
    第9章 数据查询基础
    数据库前三章测试题
    用表组织数据
    程序数据集散地:数据库
    深入C#的String类
    线程池
    hadoop-2.8.0 完全分布式运行模式
  • 原文地址:https://www.cnblogs.com/ccku/p/13699024.html
Copyright © 2011-2022 走看看