我想使用此图像 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" ]
系统CTL不起作用:
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.
这是一个著名的图像,有人找到解决方案吗?
"httpd"作为容器的PID-1运行。
如果你做"docker stop (container(",那么httpd将得到一个SIGTERM。如果你执行"docker restart (container(",那么它将循环通过docker-stop/docker-start,也重新创建httpd守护进程。
https://docs.docker.com/engine/reference/commandline/restart/
这里不需要在容器中使用 systemd。如果你真的想这样做,那么有多种选择。它可以是在容器中运行完整的 systemd,也可以改用另一个服务管理器。
https://github.com/gdraheim/docker-systemctl-images/blob/master/centos-httpd.dockerfile