systemctl command doesn't work inside of amazonlinux:latest container

0

When running "docker run --rm amazonlinux systemctl --version" to pull the latest amazon linux 2 docker container and checking the version of systemctl, I get this output:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "systemctl": executable file not found in $PATH": unknown.

However I would expect a similar output for pulling the latest centos container like when running "docker run --rm centos systemctl --version" which gives me the output:

systemd 239
_PAM _AUDIT _SELINUX _IMA -APPARMOR _SMACK _SYSVINIT _UTMP _LIBCRYPTSETUP _GCRYPT _GNUTLS _ACL _XZ _LZ4 _SECCOMP _BLKID _ELFUTILS _KMOD _IDN2 -IDN +PCRE2 default-hierarchy=legacy

The systemctl command even works when trying it on an amazon linux 2 AMI, so I'm not sure why this doesn't work for the docker container. Also, I know that I am pulling an amazon linux 2 docker image from the command above because when I run "docker run --rm amazonlinux cat /etc/os-release" to print out the OS details I see:

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/"

gefragt vor 4 Jahren3250 Aufrufe
2 Antworten
0

By default, systemd is not installed in the Amazon Linux 2 container image.

Try this:

 yum install -y /usr/bin/systemctl; systemctl --version
AWS
beantwortet vor 4 Jahren
0

This is a non-fully tested solution, but solves me the problem on amazonlinux:1 who it is under EOL extended window time (consider this solution as your own risk):

cat /etc/os-release | grep CPE_NAME
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"

curl -o /usr/local/bin/systemctl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py\
    && chmod +x /usr/local/bin/systemctl

systemctl --version

systemd 219
  - via systemctl.py 1.5.7113
-PAM -AUDIT -SELINUX -IMA -APPARMOR -SMACK +SYSVINIT -UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL -XZ -LZ4 -SECCOMP -BLKID -ELFUTILS -KMOD -IDN
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen