Hi, systemctl by default is not installed in the docker image. You can try to start the http service using something like /usr/sbin/httpd -DFOREGROUND. Dockerfile could be updated to ``` FROM amazonlinux:latest RUN yum install httpd -y ENTRYPOINT ["/usr/sbin/httpd"] CMD ["-DFOREGROUND"] ``` --Syd Answer from Syd on repost.aws
🌐
GitHub
github.com › robertdebock › docker-amazonlinux-systemd
GitHub - robertdebock/docker-amazonlinux-systemd: Container to test Ansible roles in, including capabilities to use systemd facilities · GitHub
This Dockerfile can build containers capable to use systemd. This repository has multiple branches that relate to amazonlinux versions.
Author   robertdebock
🌐
Software Development
softwaredevelopment.io › home › using systemd in a docker container
Using systemd in a docker container - Software Development
January 21, 2020 - FROM amazonlinux RUN yum install systemd -y CMD [“/sbin/init”] Build the docker container using the “docker build” command.
Discussions

How to run AmazonLinux 2023 on a local Docker host?
I am building processes for using AmazonLinux and I want to do it on a local machine to simplify setup. Unfortunately, I have not been able to get the official amazonlinux image from hub.docker.com... More on repost.aws
🌐 repost.aws
4
0
June 26, 2024
systemctl command doesn't work inside of amazonlinux:latest container
However I would expect a similar ... 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 ... More on repost.aws
🌐 repost.aws
2
0
March 19, 2020
systemd - Error running systemctl to start service in Amazon Linux 2 - Stack Overflow
I am trying to build a simple Apache/PHP server using the Amazon Linux 2 image. I have the following: Dockerfile FROM amazonlinux:2 RUN amazon-linux-extras install epel -y &&\ amazon-l... More on stackoverflow.com
🌐 stackoverflow.com
docker - amazonlinux:2 systemctl Failed to get D-Bus connection - Stack Overflow
Yes, as a general rule systemctl just doesn't work in Docker (and similarly service and directly running /etc/init.d scripts won't do what you expect). The container is the HTTP daemon; you don't need to try to run systemd commands, get a shell inside it, or other similar tasks you'd do on a full Linux ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Docker Hub
hub.docker.com › r › robertdebock › amazonlinux
robertdebock/amazonlinux - Docker Image
This Dockerfile can build containers capable to use systemd. This repository has multiple branches that relate to amazonlinux versions.
🌐
GitHub
gist.github.com › thimslugga › 36019e15b2a47a48c495b661d18faa6d
Setup Docker on Amazon Linux 2023 · GitHub
sudo systemctl daemon-reload sudo systemctl try-reload-or-restart systemd-journald.service sudo systemctl status systemd-journald.service ... # Disable the AL2023 MOTD banner (found at /usr/lib/motd.d/30-banner): sudo ln -s /dev/null /etc/motd.d/30-banner cat <<'EOF' | sudo tee /etc/motd.d/31-banner , #_ ~\_ ####_ ~~ \_#####\ ~~ \###| ~~ \#/ ___ Amazon Linux 2023 (Docker Optimized) ~~ V~' '-> ~~~ / ~~._.
🌐
GitHub
github.com › compwright › amazonlinux-2023-systemd
GitHub - compwright/amazonlinux-2023-systemd
Running systemd inside docker has historically been very difficult to nearly impossible. However, this has become substantially easier in recent years due to advances in Docker, the Linux kernel, systemd, and distros that use them—such as Amazon Linux 2023 (loosely based on Fedora).
Author   compwright
🌐
GitHub
github.com › robertdebock › docker-amazonlinux-systemd › blob › master › README.md
docker-amazonlinux-systemd/README.md at master · robertdebock/docker-amazonlinux-systemd
This Dockerfile can build containers capable to use systemd. This repository has multiple branches that relate to amazonlinux versions.
Author   robertdebock
🌐
AWS re:Post
repost.aws › questions › QUnFHdVih-Q1CdxH47nU1OZw › systemctl-command-doesn-t-work-inside-of-amazonlinux-latest-container
systemctl command doesn't work inside of amazonlinux:latest container | AWS re:Post
March 19, 2020 - However I would expect a similar ... 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 ...
Find elsewhere
🌐
DEV Community
dev.to › mandraketech › systemd-crond-and-docker-container-1mob
systemd, crond and Docker Container - DEV Community
May 24, 2023 - This required me to create a Dockerfile that would install the systemd service, and cronie to run cron jobs. FROM amazonlinux:2023 # Install required packages RUN yum -y update && \ yum -y install systemd cronie tar gzip git && \ systemctl enable crond.service
🌐
Docker Hub
hub.docker.com › r › ywatase › amazonlinux-systemd
ywatase/amazonlinux-systemd - Docker Image
Docker image of Amazon Linux 2 with systemd · Image · 0 · 206 · OverviewTags · Docker image of Amazon Linux 2 with systemd · Dockerでsystemdを起動する方法はCentOSを参考に作成しています。 · centos/systemd⁠ Dockerfile - centos/systemd⁠ ·
🌐
GitHub
github.com › buluma › docker-amazonlinux-systemd
GitHub - buluma/docker-amazonlinux-systemd: Amazon Linux Container to test Ansible roles in, including capabilities to use systemd facilities.
Amazon Linux Container to test Ansible roles in, including capabilities to use systemd facilities. - buluma/docker-amazonlinux-systemd
Author   buluma
🌐
Stack Overflow
stackoverflow.com › questions › 61920143 › amazonlinux2-systemctl-failed-to-get-d-bus-connection
docker - amazonlinux:2 systemctl Failed to get D-Bus connection - Stack Overflow
Yes, as a general rule systemctl just doesn't work in Docker (and similarly service and directly running /etc/init.d scripts won't do what you expect). The container is the HTTP daemon; you don't need to try to run systemd commands, get a shell ...
🌐
DEV Community
dev.to › dasanirban834 › docker-installation-on-amazon-linux-2-or-amazon-linux-2023-5afa
Docker: Installation on Amazon Linux 2 or Amazon Linux 2023 - DEV Community
September 8, 2024 - Linux: https://docs.docker.com/desktop/install/linux-install/ MAC: https://docs.docker.com/desktop/install/mac-install/ Windows: https://docs.docker.com/desktop/install/windows-install/ ... [root@docker ~]# systemctl status docker ● docker.service ...
Top answer
1 of 2
23

Using Amazon Linux 2 I tried to replicate the issue. Obviously, I don't have all the dependencies to run your exact docker-compose.yml, thus I used the docker-compose.yml from here for my verification. The file setups wordpress with mysql .

Steps I took were following (executed as ec2-user in home folder):

1. Install docker

sudo yum update -y  
sudo yum install -y docker
sudo systemctl enable docker
sudo systemctl start docker

2. Install docker-compose

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/bin/docker-compose

sudo chmod +x /usr/bin/docker-compose

3. Create docker-compose.yml

mkdir myapp 

Create file ./myapp/docker-compose.yml:

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

4. Create docker_boot.service

The file is different then yours, as there were few potential issues in your file:

  • not using absolute paths
  • ec2-user may have no permissions to run docker

Create file ./myapp/docker_boot.service:

[Unit]
Description=docker boot
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/ec2-user/myapp
ExecStart=/usr/bin/docker-compose -f /home/ec2-user/myapp/docker-compose.yml up -d --remove-orphans

[Install]
WantedBy=multi-user.target

5. Copy docker_boot.service to systemd

sudo cp -v ./myapp/docker_boot.service /etc/systemd/system

6. Enable and start docker_boot.service

sudo systemctl enable docker_boot.service
sudo systemctl start docker_boot.service

Note: First start may take some time, as it will pull all docker images required. Alternatively start docker-compose manually first to avoid this.

7. Check status of the docker_boot.service

sudo systemctl status docker_boot.service

8. Check if the wordpress is up

curl -L localhost:8000

9. Reboot

Check if the docker_boot.service is running after instance reboot by logging in into the instance and using sudo systemctl status docker_boot.service and/or curl -L localhost:8000.

2 of 2
5

To have a service launch at launch you would run the following command sudo systemctl enable docker.

For having it then launch your docker compose up -d command you'd need to create a new service for your specific action, and then enable it with the contents similar to the below.

[Unit]
After=docker.service
Description=Docker compose

[Service]
ExecStart=docker-compose up -d

[Install]
WantedBy=multi-user.target

More information for this is available in this post.

🌐
Docker Hub
hub.docker.com › _ › amazonlinux
amazonlinux - Official Image | Docker Hub
Amazon Linux Docker container images contain a subset of the packages in the images for use on EC2 and as VMs in on-premises scenarios. The container images can be configured to use any of the full set of packages in images for EC2 and on-premises use. Similar to the Amazon Linux images for ...
🌐
GitHub
github.com › topics › amazonlinux
Build software better, together
Docker images for testing Ansible roles across multiple Linux distributions. Multi-arch (linux/amd64, linux/arm64) builds for Debian, Ubuntu, Fedora, Rocky Linux, Amazon Linux, and Alpine.
🌐
GitHub
github.com › robertdebock › docker-amazonlinux-systemd › blob › master › Dockerfile
docker-amazonlinux-systemd/Dockerfile at master · robertdebock/docker-amazonlinux-systemd
FROM amazonlinux · · LABEL maintainer="Robert de Bock <robert@meinit.nl>" LABEL build_date="2024-07-01" · ENV container=docker · · RUN yum -y install systemd ; \ 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/* ·
Author   robertdebock
🌐
Reddit
reddit.com › r/docker › docker and amazon linux 2 issues.
r/docker on Reddit: Docker and Amazon Linux 2 issues.
January 29, 2018 -

Any tips / links to help get docker and AMI v2 (Amazon Linux 2 LTS Candidate AMI 2017.12.0 ). I'm looking to leverage Amazon Linux 2 and docker. Anyone have a pointer to get docker daemon to start automatically. I've walked through a few tutorials and when I type docker version, the daemon isn't running. I've added the ec2-user to the docker group. Rebooted...

ec2-user@ip-10-0-0-90 ~$ systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/docker.service.d └─override.conf Active: failed (Result: start-limit) since Sun 2018-01-28 18:24:10 UTC; 27min ago Docs: https://docs.docker.com Process: 3927 ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock (code=exited, status=1/FAILURE) Main PID: 3927 (code=exited, status=1/FAILURE)

Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: Failed to start Docker Application Container Engine. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: Unit docker.service entered failed state. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: docker.service failed. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: docker.service holdoff time over, scheduling restart. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: start request repeated too quickly for docker.service Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: Failed to start Docker Application Container Engine. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: Unit docker.service entered failed state. Jan 28 18:24:10 ip-10-0-0-90.ec2.internal systemd[1]: docker.service failed.