====== Apache httpd von Docker ======
siehe https://hub.docker.com/_/httpd
===== persistente Daten für den Container anlegen =====
++++ Podman |
Wenn SELinux aktiv ist, vielleicht ''/var/lib/containers'' anstelle von ''/srv/docker'' verwenden. Da sind die passenden Berechtigungen bereits gesetzt.
++++
mkdir -p /srv/docker/httpd/htdocs
cd /srv/docker/httpd
Hello World!
Hello World
===== erster Start =====
++++ podman |
Wenn SELinux aktiv ist '':Z'' hinzufügen. Das veranlasst Podman, das Volume mit einem privaten SELinux-Kontext zu relabeln, wodurch der Container Zugriff darauf erhält.
podman run -d --name hello-httpd -p 8888:80 -v '/srv/docker/httpd/htdocs:/usr/local/apache2/htdocs/:Z' httpd:2.4
++++
docker container run -d --name hello-httpd -p 8888:80 -v '/srv/docker/httpd/htdocs:/usr/local/apache2/htdocs/' httpd:2.4
-> http://localhost:8888
curl http://localhost:8888
WorkingDir herausfinden: (( oder mit ''jq'':
docker container inspect hello-httpd | jq -r '.[].Config.WorkingDir'
))
docker container inspect -f '{{.Config.WorkingDir}}' hello-httpd
Mounts herausfinden:
docker container inspect -f '{{ json .Mounts }}' hello-httpd | jq
Betreten des Containers:
docker container exec -it hello-httpd /bin/bash
ls conf/httpd.conf
exit
Container löschen:
docker container rm -f hello-httpd
===== Start mit eigener Konfigurationsdatei =====
==== mit Konfigurationsdatei im Volume ====
Extrahieren der Konfigurationsdatei:
cd /srv/docker/httpd
docker container run --rm httpd:2.4 cat /usr/local/apache2/conf/httpd.conf > httpd.conf
Konfigurationsdatei bearbeiten:
sed -i.bak 's/^Listen 80/Listen 8001/' httpd.conf
diff httpd.conf{,.bak}
Starten:
docker container run -d --name httpd_8001 -p 8888:8001 -v '/srv/docker/httpd/htdocs:/usr/local/apache2/htdocs/' -v '/srv/docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf' httpd:2.4
-> http://localhost:8888
Container löschen:
docker container rm -f httpd_8001
==== mit Dockerfile ====
FROM httpd:2.4
RUN sed -i.bak 's/^Listen 80/Listen 8001/' /usr/local/apache2/conf/httpd.conf
EXPOSE 8001/tcp
docker build -t='ingo/apache:0.0.1' .
docker container run -d -P ingo/apache:0.0.1
docker container ls
-> ''->8001/tcp''
Problem: im Image ''httpd:2.4'' steht ''EXPOSE 80/tcp''. Um das zu ändern, muss man ein neues Image erzeugen und alle relevanten Instruktionen neu setzen. (Oder man ignoriert es, ''EXPOSE'' dient nur der Dokumentation.)
docker image inspect
-> altes ''expose'' ist noch enthalten
++++ Das zu lösen ist komplizierter|
docker image history --no-trunc httpd:2.4
-> alle Anweisungen rauskopieren, die im neuen Image enthalten sein sollen
FROM httpd:2.4 AS build
RUN sed -i.bak 's/^Listen 80/Listen 8001/' /usr/local/apache2/conf/httpd.conf
FROM scratch
COPY --from=build / /
ENV HTTPD_PREFIX=/usr/local/apache2
ENV PATH=/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV HTTPD_VERSION=2.4.66
ENV HTTPD_SHA256=94d7ff2b42acbb828e870ba29e4cbad48e558a79c623ad3596e4116efcfea25a
ENV HTTPD_PATCHES=
CMD ["httpd-foreground"]
EXPOSE 8001/tcp
docker build -t='ingo/apache:0.0.1' .
docker container run -d -P ingo/apache:0.0.1
docker container ls
-> ''->8001/tcp''
++++