How to run AmazonLinux 2023 on a local Docker host?

0

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 to run under Docker. Any suggestions?

ADDED 27 Jun 2024

The goal is to have a container that I can turn on and then see how it works. For example, these containers don't have common Linux/Unix tools like "ps", so normal system administration processes may fail. If I run the container without adding a process like httpd, the container starts up and then dies. I need the container to start up and stay up.

Dockerfile

FROM amazonlinux:latest
RUN yum install httpd -y
RUN systemctl start httpd
RUN systemctl enable httpd
ENTRYPOINT ["/bin/bash"]

Command

docker build -t amzl_web .

Error

[+] Building 2.6s (6/7)                                                              docker:default
 => [internal] load build definition from Dockerfile                                           0.3s
 => => transferring dockerfile: 295B                                                           0.1s
 => [internal] load .dockerignore                                                              0.2s
 => => transferring context: 2B                                                                0.0s
 => [internal] load metadata for docker.io/library/amazonlinux:latest                          0.0s
 => [1/4] FROM docker.io/library/amazonlinux:latest                                            0.0s
 => CACHED [2/4] RUN yum install httpd -y                                                      0.0s
 => ERROR [3/4] RUN systemctl start httpd                                                      1.6s
------                                                                                              
 > [3/4] RUN systemctl start httpd:                                                                 
1.185 System has not been booted with systemd as init system (PID 1). Can't operate.
1.185 Failed to connect to bus: Host is down
------
Dockerfile:5
--------------------
   4 |     RUN yum install httpd -y
   5 | >>> RUN systemctl start httpd
   6 |     RUN systemctl enable httpd
--------------------
ERROR: failed to solve: process "/bin/sh -c systemctl start httpd" did not complete successfully: exit code: 1
Leam
asked 2 months ago452 views
3 Answers
1
Accepted Answer

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

profile picture
Syd
answered a month ago
  • Hey Syd, that keeps it running, but I can't attach to it. Any suggestions?

  • If you mean how to attach to running container, you need to use docker exec from another terminal.

    docker exec -it container_id sh
    

    You can get the container id from docker ps output

0

Hello.

How about acquiring the Amazon Linux 2023 Docker image from ECR using the steps in the document below?
https://docs.aws.amazon.com/linux/al2023/ug/base-container.html

profile picture
EXPERT
answered 2 months ago
AWS
EXPERT
Mike_L
reviewed 2 months ago
profile pictureAWS
EXPERT
reviewed 2 months ago
  • Thanks! I've tried both the Docker Hub image, and the one from public.ecr.aws. Both seem to have the issue.

0

Hi,

You can also download the official AL2023 Docker image directly from Docker Hub if more convenient for you.

It's there: https://hub.docker.com/_/amazonlinux

Enter image description here

Please, note the "Docker Official Image" badge: it means that it a curated image on which you can rely.

Best,

Didier

profile pictureAWS
EXPERT
answered 2 months ago
AWS
EXPERT
Mike_L
reviewed 2 months ago
  • That is the one that's not working. See additions to the question.