微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 centos Docker 中使用 Systemctl 命令

如何解决无法在 centos Docker 中使用 Systemctl 命令

我尝试在 docker 容器中安装 httpd,并尝试通过 docker 中的 systemctl 重新启动 httpd。但我遇到了如下异常

enter image description here

根据我的分析,docker 基础镜像中认没有启用 systemctl,专家建议如下配置。

    FROM centos:7

ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done);
rm -f /lib/systemd/system/multi-user.target.wants/;
rm -f /etc/systemd/system/.wants/;
rm -f /lib/systemd/system/local-fs.target.wants/;
rm -f /lib/systemd/system/sockets.target.wants/udev;
rm -f /lib/systemd/system/sockets.target.wants/initctl;
rm -f /lib/systemd/system/basic.target.wants/;
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ “/sys/fs/cgroup” ]
CMD ["/usr/sbin/init"]

我尝试了同样的方法,但仍然没有运气。我尝试使用 centos/systemd 作为我的基本映像的另一种选择,但没有运气。这是我正在尝试的示例 docker 文件

FROM centos:7
    
RUN  yum -y install httpd PHP PHP-MysqL PHP-gd mariadb-server PHP-xml PHP-intl MysqL weget

RUN systemctl restart httpd.service

RUN  systemctl enable httpd.service
RUN  systemctl start mariadb 

RUN systemctl enable mariadb 

# RUN  MysqL -u root -p -u root

EXPOSE 80

有人请教我吗?还有其他可能以不同的方式实现相同的目标吗?

参考文献:

Docker CentOS systemctl not permitted https://forums.docker.com/t/systemctl-status-is-not-working-in-my-docker-container/9075/2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。