【发布时间】:2020-09-07 05:38:57
【问题描述】:
我想使用此图像 https://hub.docker.com/_/amazonlinux 为我的 EC2 机器编写脚本
这是我的 Dockefile :
FROM amazonlinux:2
MAINTAINER "xxxxx" <xxxxx@xxxx.xx>
RUN yum -y update
RUN yum -y install httpd
WORKDIR /var/www/html
CMD [ "/usr/sbin/httpd","-D","FOREGROUND" ]
systemctl 不起作用:
bash-4.2# systemctl list-units
Failed to get D-Bus connection: Operation not permitted
bash-4.2# systemctl status httpd.service
Failed to get D-Bus connection: Operation not permitted
我无法重启
bash-4.2# systemctl restart httpd.service
Failed to get D-Bus connection: Operation not permitted
/etc/os-release
bash-4.2# cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
在真正的 ec2 上没问题:
[ec2-user@ip-xxxxxxxxx]$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
[ec2-user@ip-xxxxxxxxx]$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since mer. 2020-05-20 16:36:19 UTC; 1h 50min ago
Docs: man:httpd.service(8)
Main PID: 3047 (httpd)
Status: "Total requests: 7; Idle/Busy workers 100/0;Requests/sec: 0.00106; Bytes served/sec: 20 B/sec"
CGroup: /system.slice/httpd.service
├─3047 /usr/sbin/httpd -DFOREGROUND
├─3075 /usr/sbin/httpd -DFOREGROUND
├─3076 /usr/sbin/httpd -DFOREGROUND
├─3077 /usr/sbin/httpd -DFOREGROUND
├─3078 /usr/sbin/httpd -DFOREGROUND
├─3079 /usr/sbin/httpd -DFOREGROUND
└─3495 /usr/sbin/httpd -DFOREGROUND
mai 20 16:36:19 xxxxxxxxx.internal systemd[1]: Starting The Apache HTTP Server...
mai 20 16:36:19 xxxxxxxxx.internal systemd[1]: Started The Apache HTTP Server.
这是一个著名的图像,有没有人找到解决方案?
【问题讨论】:
-
是的,作为一般规则
systemctl在 Docker 中不起作用(同样service和直接运行/etc/init.d脚本不会达到您的预期)。容器是 HTTP 守护进程;您无需尝试运行 systemd 命令、在其中获取 shell 或在完整的 Linux VM 上执行的其他类似任务。
标签: docker amazon-ec2 systemctl