Compare commits
10 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3536d1cb14 | ||
|
|
796802d01e | ||
|
|
3d43c2d542 | ||
|
|
bc543686ef | ||
|
|
6bb7bfd4a6 | ||
|
|
3cc5a1726f | ||
|
|
70528df32f | ||
|
|
f252beb263 | ||
|
|
47d7acf8d4 | ||
|
|
0000b8d8b8 |
17 changed files with 944 additions and 1 deletions
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
68
Dockerfile
Normal file
68
Dockerfile
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
FROM registry.fedoraproject.org/f25/s2i-base
|
||||
|
||||
# Apache HTTP Server image.
|
||||
#
|
||||
# Volumes:
|
||||
# * /var/www - Datastore for httpd
|
||||
# * /var/log/httpd - Storage for logs when $HTTPD_LOG_TO_VOLUME is set
|
||||
# Environment:
|
||||
# * $HTTPD_LOG_TO_VOLUME (optional) - When set, httpd will log into /var/log/httpd
|
||||
|
||||
ENV HTTPD_VERSION=2.4
|
||||
|
||||
ENV SUMMARY="Platform for running Apache httpd $HTTPD_VERSION or building httpd-based application" \
|
||||
DESCRIPTION="Apache httpd $HTTPD_VERSION available as docker container, is a powerful, efficient, \
|
||||
and extensible web server. Apache supports a variety of features, many implemented as compiled modules \
|
||||
which extend the core functionality. \
|
||||
These can range from server-side programming language support to authentication schemes. \
|
||||
Virtual hosting allows one Apache installation to serve many different Web sites."
|
||||
|
||||
LABEL summary="$SUMMARY" \
|
||||
description="$DESCRIPTION" \
|
||||
io.k8s.description="$SUMMARY" \
|
||||
io.k8s.display-name="Apache httpd $HTTPD_VERSION" \
|
||||
io.openshift.expose-services="8080:http,8443:https" \
|
||||
io.openshift.tags="builder,httpd,httpd24"
|
||||
|
||||
ENV NAME=httpd VERSION=0 RELEASE=11 ARCH=x86_64
|
||||
|
||||
LABEL com.redhat.component="$NAME" \
|
||||
name="$FGC/$NAME" \
|
||||
version="$VERSION" \
|
||||
release="$RELEASE.$DISTTAG" \
|
||||
architecture="$ARCH" \
|
||||
usage="docker run -d --name httpd -p 8080:8080 -v /wwwdata:/var/www:Z 25/httpd" \
|
||||
help="help.1"
|
||||
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
EXPOSE 8080
|
||||
EXPOSE 8443
|
||||
|
||||
RUN dnf install -y yum-utils gettext hostname && \
|
||||
INSTALL_PKGS="nss_wrapper bind-utils httpd mod_ssl" && \
|
||||
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
|
||||
rpm -V $INSTALL_PKGS && \
|
||||
dnf clean all
|
||||
|
||||
ENV HTTPD_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/httpd/ \
|
||||
HTTPD_APP_ROOT=/opt/app-root \
|
||||
HTTPD_CONFIGURATION_PATH=${HTTPD_APP_ROOT}/etc/httpd.d \
|
||||
HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \
|
||||
HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \
|
||||
HTTPD_VAR_RUN=/var/run/httpd \
|
||||
HTTPD_DATA_PATH=/var/www \
|
||||
HTTPD_DATA_ORIG_PATH=/var/www \
|
||||
HTTPD_LOG_PATH=/var/log/httpd
|
||||
|
||||
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
|
||||
COPY ./root /
|
||||
|
||||
RUN /usr/libexec/httpd-prepare
|
||||
|
||||
USER 1001
|
||||
|
||||
VOLUME ["${HTTPD_DATA_PATH}"]
|
||||
VOLUME ["${HTTPD_LOG_PATH}"]
|
||||
|
||||
CMD ["/usr/bin/run-httpd"]
|
||||
121
README.md
Normal file
121
README.md
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
Apache HTTP Server 2.4
|
||||
======================
|
||||
|
||||
This container image includes Apache HTTP Server 2.4 for OpenShift and general usage.
|
||||
Users can choose between RHEL, CentOS, and Fedora based images.
|
||||
The RHEL image is available in the [Red Hat Registry](https://access.redhat.com/containers)
|
||||
as registry.access.redhat.com/rhscl/httpd-24-rhel7.
|
||||
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/centos/httpd-24-centos7/)
|
||||
as centos/httpd-24-centos7.
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
Apache HTTP Server 2.4 available as docker container, is a powerful, efficient,
|
||||
and extensible web server. Apache supports a variety of features, many implemented as compiled modules
|
||||
which extend the core functionality.
|
||||
These can range from server-side programming language support to authentication schemes.
|
||||
Virtual hosting allows one Apache installation to serve many different Web sites."
|
||||
|
||||
|
||||
USAGE
|
||||
-----
|
||||
|
||||
For this, we will assume that you are using the `rhscl/httpd-24-rhel7` image.
|
||||
The image can be used as a base image for other applications based on Apache HTTP web server.
|
||||
|
||||
An example of the data on the host for both the examples above, that will be served by
|
||||
Apache HTTP web server:
|
||||
|
||||
```
|
||||
$ ls -lZ /wwwdata/html
|
||||
-rw-r--r--. 1 1001 1001 54321 Jan 01 12:34 index.html
|
||||
-rw-r--r--. 1 1001 1001 5678 Jan 01 12:34 page.html
|
||||
```
|
||||
|
||||
If you want to run the image and mount the static pages available in `/wwwdata` on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d --name httpd -p 8080:8080 -v /wwwdata:/var/www:Z rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
This will create a container named `httpd` running Apache HTTP Server, serving data from
|
||||
`/wwwdata` directory. Port 8080 will be exposed and mapped to the host.
|
||||
|
||||
If you want to create a new Docker layered image, use [Source-to-Image](https://github.com/openshift/source-to-image), a tool for building/building artifacts from source and injecting into docker images. To create a new Docker image named `httpd-app` using Source-to-Image, while using data available in `/wwwdata` on the host, execute the following command:
|
||||
|
||||
```
|
||||
$ s2i build file:///wwwdata/html rhscl/httpd-24-rhel7 httpd-app
|
||||
```
|
||||
|
||||
To run such a new image, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d --name httpd -p 8080:8080 httpd-app
|
||||
```
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
The Apache HTTP Server container image supports the following configuration variable, which can be set by using the `-e` option with the docker run command:
|
||||
|
||||
| Variable name | Description |
|
||||
| :---------------------- | ----------------------------------------- |
|
||||
| `HTTPD_LOG_TO_VOLUME` | By default, httpd logs into standard output, so the logs are accessible by using the docker logs command. When `HTTPD_LOG_TO_VOLUME` is set, httpd logs into `/var/log/httpd24`, which can be mounted to host system using the Docker volumes. This option is only allowed when container is run as UID 0. |
|
||||
|
||||
|
||||
If you want to run the image and mount the log files into `/wwwlogs` on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d -u 0 -e HTTPD_LOG_TO_VOLUME=1 --name httpd -v /wwwlogs:/var/log/httpd24:Z rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
|
||||
VOLUMES
|
||||
-------
|
||||
|
||||
You can also set the following mount points by passing the `-v /host:/container` flag to Docker.
|
||||
|
||||
| Volume mount point | Description |
|
||||
| :----------------------- | ---------------------------------------------------------------------- |
|
||||
| `/var/www` | Apache HTTP Server data directory |
|
||||
| `/var/log/httpd24` | Apache HTTP Server log directory (available only when running as root, path `/var/log/httpd` is used in case of Fedora based image) |
|
||||
|
||||
**Notice: When mouting a directory from the host into the container, ensure that the mounted
|
||||
directory has the appropriate permissions and that the owner and group of the directory
|
||||
matches the user UID or name which is running inside the container.**
|
||||
|
||||
|
||||
DEFAULT USER
|
||||
------------
|
||||
|
||||
By default, Apache HTTP Server container runs as UID 1001. That means the volume mounted directories for the files (if mounted using `-v` option) need to be prepared properly, so the UID 1001 can read them.
|
||||
|
||||
To run the container as a different UID, use `-u` option. For example if you want to run the container as UID 1234, execute the following command:
|
||||
|
||||
```
|
||||
docker run -d -u 1234 rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
To log into a volume mounted directory, the container needs to be run as UID 0 (see above).
|
||||
|
||||
|
||||
|
||||
TROUBLESHOOTING
|
||||
---------------
|
||||
The httpd deamon in the container logs to the standard output by default, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
docker logs <container>
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
Dockerfile and other sources for this container image are available on
|
||||
https://github.com/sclorg/httpd-container.
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
This container component is no longer used for anything, retiring to make it explicit.
|
||||
163
root/help.1
Normal file
163
root/help.1
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
.TH "HTTPD-24-RHEL7" "1" " Container Image Pages" "Red Hat" "April 07, 2017" ""
|
||||
|
||||
|
||||
.SH Apache HTTP Server 2.4
|
||||
.PP
|
||||
This container image includes Apache HTTP Server 2.4 for OpenShift and general usage.
|
||||
Users can choose between RHEL, CentOS, and Fedora based images.
|
||||
The RHEL image is available in the
|
||||
\[la]https://access.redhat.com/containers\[ra]
|
||||
as registry.access.redhat.com/rhscl/httpd\-24\-rhel7.
|
||||
The CentOS image is then available on
|
||||
\[la]https://hub.docker.com/r/centos/httpd-24-centos7/\[ra]
|
||||
as centos/httpd\-24\-centos7.
|
||||
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
Apache HTTP Server 2.4 available as docker container, is a powerful, efficient,
|
||||
and extensible web server. Apache supports a variety of features, many implemented as compiled modules
|
||||
which extend the core functionality.
|
||||
These can range from server\-side programming language support to authentication schemes.
|
||||
Virtual hosting allows one Apache installation to serve many different Web sites."
|
||||
|
||||
.SH USAGE
|
||||
.PP
|
||||
For this, we will assume that you are using the \fB\fCrhscl/httpd\-24\-rhel7\fR image.
|
||||
The image can be used as a base image for other applications based on Apache HTTP web server.
|
||||
|
||||
.PP
|
||||
An example of the data on the host for both the examples above, that will be served by
|
||||
Apache HTTP web server:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ ls \-lZ /wwwdata/html
|
||||
\-rw\-r\-\-r\-\-. 1 1001 1001 54321 Jan 01 12:34 index.html
|
||||
\-rw\-r\-\-r\-\-. 1 1001 1001 5678 Jan 01 12:34 page.html
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
If you want to run the image and mount the static pages available in \fB\fC/wwwdata\fR on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ docker run \-d \-\-name httpd \-p 8080:8080 \-v /wwwdata:/var/www:Z rhscl/httpd\-24\-rhel7
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
This will create a container named \fB\fChttpd\fR running Apache HTTP Server, serving data from
|
||||
\fB\fC/wwwdata\fR directory. Port 8080 will be exposed and mapped to the host.
|
||||
|
||||
.PP
|
||||
If you want to create a new Docker layered image, use
|
||||
\[la]https://github.com/openshift/source-to-image\[ra], a tool for building/building artifacts from source and injecting into docker images. To create a new Docker image named \fB\fChttpd\-app\fR using Source\-to\-Image, while using data available in \fB\fC/wwwdata\fR on the host, execute the following command:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ s2i build file:///wwwdata/html rhscl/httpd\-24\-rhel7 httpd\-app
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
To run such a new image, execute the following command:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ docker run \-d \-\-name httpd \-p 8080:8080 httpd\-app
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH CONFIGURATION
|
||||
.PP
|
||||
The Apache HTTP Server container image supports the following configuration variable, which can be set by using the \fB\fC\-e\fR option with the docker run command:
|
||||
.TS
|
||||
allbox;
|
||||
Variable name Description
|
||||
\fB\fCHTTPD\_LOG\_TO\_VOLUME\fR By default, httpd logs into standard output, so the logs are accessible by using the docker logs command. When \fB\fCHTTPD\_LOG\_TO\_VOLUME\fR is set, httpd logs into \fB\fC/var/log/httpd24\fR, which can be mounted to host system using the Docker volumes. This option is only allowed when container is run as UID 0.
|
||||
|
||||
.TE
|
||||
|
||||
.PP
|
||||
If you want to run the image and mount the log files into \fB\fC/wwwlogs\fR on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ docker run \-d \-u 0 \-e HTTPD\_LOG\_TO\_VOLUME=1 \-\-name httpd \-v /wwwlogs:/var/log/httpd24:Z rhscl/httpd\-24\-rhel7
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH VOLUMES
|
||||
.PP
|
||||
You can also set the following mount points by passing the \fB\fC\-v /host:/container\fR flag to Docker.
|
||||
.TS
|
||||
allbox;
|
||||
Volume mount point Description
|
||||
\fB\fC/var/www\fR Apache HTTP Server data directory
|
||||
|
||||
\fB\fC/var/log/httpd24\fR Apache HTTP Server log directory (available only when running as root, path \fB\fC/var/log/httpd\fR is used in case of Fedora based image)
|
||||
|
||||
.TE
|
||||
|
||||
.PP
|
||||
\fBNotice: When mouting a directory from the host into the container, ensure that the mounted
|
||||
directory has the appropriate permissions and that the owner and group of the directory
|
||||
matches the user UID or name which is running inside the container.\fP
|
||||
|
||||
.SH DEFAULT USER
|
||||
.PP
|
||||
By default, Apache HTTP Server container runs as UID 1001. That means the volume mounted directories for the files (if mounted using \fB\fC\-v\fR option) need to be prepared properly, so the UID 1001 can read them.
|
||||
|
||||
.PP
|
||||
To run the container as a different UID, use \fB\fC\-u\fR option. For example if you want to run the container as UID 1234, execute the following command:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
docker run \-d \-u 1234 rhscl/httpd\-24\-rhel7
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
To log into a volume mounted directory, the container needs to be run as UID 0 (see above).
|
||||
|
||||
.SH TROUBLESHOOTING
|
||||
.PP
|
||||
The httpd deamon in the container logs to the standard output by default, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
docker logs <container>
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
Dockerfile and other sources for this container image are available on
|
||||
|
||||
\[la]https://github.com/sclorg/httpd-container\[ra].
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
16
root/usr/bin/run-httpd
Executable file
16
root/usr/bin/run-httpd
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh
|
||||
|
||||
# Check whether we run as s2i
|
||||
if ! [ -v HTTPD_RUN_BY_S2I ] && runs_privileged ; then
|
||||
config_privileged
|
||||
else
|
||||
# We run as non-root or as s2i
|
||||
config_non_privileged
|
||||
generate_container_user
|
||||
fi
|
||||
|
||||
exec httpd -D FOREGROUND $@
|
||||
36
root/usr/libexec/httpd-prepare
Executable file
36
root/usr/libexec/httpd-prepare
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh
|
||||
|
||||
# compatibility symlinks so we hide SCL paths
|
||||
if [ -v HTTPD_SCL ] ; then
|
||||
# /opt/rh/httpd24/root/etc/httpd will be symlink to /etc/httpd
|
||||
mv /opt/rh/httpd24/root/etc/httpd /etc/httpd
|
||||
ln -s /etc/httpd /opt/rh/httpd24/root/etc/httpd
|
||||
|
||||
# /opt/rh/httpd24/root/var/run/httpd will be symlink to /var/run/httpd
|
||||
mv /opt/rh/httpd24/root/var/run/httpd /var/run/httpd
|
||||
ln -s /var/run/httpd /opt/rh/httpd24/root/var/run/httpd
|
||||
|
||||
# /opt/rh/httpd24/root/var/www will be symlink to /var/www
|
||||
rm -rf /var/www
|
||||
mv /opt/rh/httpd24/root/var/www /var/www
|
||||
ln -s /var/www /opt/rh/httpd24/root/var/www
|
||||
fi
|
||||
|
||||
mkdir -p ${HTTPD_CONFIGURATION_PATH}
|
||||
chmod -R a+rwx ${HTTPD_MAIN_CONF_PATH}
|
||||
chmod -R a+rwx ${HTTPD_MAIN_CONF_D_PATH}
|
||||
chmod -R a+r /etc/pki/tls/certs/localhost.crt
|
||||
chmod -R a+r /etc/pki/tls/private/localhost.key
|
||||
mkdir -p ${HTTPD_APP_ROOT}/etc
|
||||
chmod -R a+rwx ${HTTPD_APP_ROOT}/etc
|
||||
chmod -R a+rwx ${HTTPD_VAR_RUN}
|
||||
chown -R 1001:0 ${HTTPD_APP_ROOT}
|
||||
chown -R 1001:0 ${HTTPD_DATA_PATH}
|
||||
chown -R 1001:0 ${HTTPD_LOG_PATH}
|
||||
|
||||
config_general
|
||||
|
||||
121
root/usr/share/container-scripts/httpd/README.md
Normal file
121
root/usr/share/container-scripts/httpd/README.md
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
Apache HTTP Server 2.4
|
||||
======================
|
||||
|
||||
This container image includes Apache HTTP Server 2.4 for OpenShift and general usage.
|
||||
Users can choose between RHEL, CentOS, and Fedora based images.
|
||||
The RHEL image is available in the [Red Hat Registry](https://access.redhat.com/containers)
|
||||
as registry.access.redhat.com/rhscl/httpd-24-rhel7.
|
||||
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/centos/httpd-24-centos7/)
|
||||
as centos/httpd-24-centos7.
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
Apache HTTP Server 2.4 available as docker container, is a powerful, efficient,
|
||||
and extensible web server. Apache supports a variety of features, many implemented as compiled modules
|
||||
which extend the core functionality.
|
||||
These can range from server-side programming language support to authentication schemes.
|
||||
Virtual hosting allows one Apache installation to serve many different Web sites."
|
||||
|
||||
|
||||
USAGE
|
||||
-----
|
||||
|
||||
For this, we will assume that you are using the `rhscl/httpd-24-rhel7` image.
|
||||
The image can be used as a base image for other applications based on Apache HTTP web server.
|
||||
|
||||
An example of the data on the host for both the examples above, that will be served by
|
||||
Apache HTTP web server:
|
||||
|
||||
```
|
||||
$ ls -lZ /wwwdata/html
|
||||
-rw-r--r--. 1 1001 1001 54321 Jan 01 12:34 index.html
|
||||
-rw-r--r--. 1 1001 1001 5678 Jan 01 12:34 page.html
|
||||
```
|
||||
|
||||
If you want to run the image and mount the static pages available in `/wwwdata` on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d --name httpd -p 8080:8080 -v /wwwdata:/var/www:Z rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
This will create a container named `httpd` running Apache HTTP Server, serving data from
|
||||
`/wwwdata` directory. Port 8080 will be exposed and mapped to the host.
|
||||
|
||||
If you want to create a new Docker layered image, use [Source-to-Image](https://github.com/openshift/source-to-image), a tool for building/building artifacts from source and injecting into docker images. To create a new Docker image named `httpd-app` using Source-to-Image, while using data available in `/wwwdata` on the host, execute the following command:
|
||||
|
||||
```
|
||||
$ s2i build file:///wwwdata/html rhscl/httpd-24-rhel7 httpd-app
|
||||
```
|
||||
|
||||
To run such a new image, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d --name httpd -p 8080:8080 httpd-app
|
||||
```
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
The Apache HTTP Server container image supports the following configuration variable, which can be set by using the `-e` option with the docker run command:
|
||||
|
||||
| Variable name | Description |
|
||||
| :---------------------- | ----------------------------------------- |
|
||||
| `HTTPD_LOG_TO_VOLUME` | By default, httpd logs into standard output, so the logs are accessible by using the docker logs command. When `HTTPD_LOG_TO_VOLUME` is set, httpd logs into `/var/log/httpd24`, which can be mounted to host system using the Docker volumes. This option is only allowed when container is run as UID 0. |
|
||||
|
||||
|
||||
If you want to run the image and mount the log files into `/wwwlogs` on the host
|
||||
as a docker volume, execute the following command:
|
||||
|
||||
```
|
||||
$ docker run -d -u 0 -e HTTPD_LOG_TO_VOLUME=1 --name httpd -v /wwwlogs:/var/log/httpd24:Z rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
|
||||
VOLUMES
|
||||
-------
|
||||
|
||||
You can also set the following mount points by passing the `-v /host:/container` flag to Docker.
|
||||
|
||||
| Volume mount point | Description |
|
||||
| :----------------------- | ---------------------------------------------------------------------- |
|
||||
| `/var/www` | Apache HTTP Server data directory |
|
||||
| `/var/log/httpd24` | Apache HTTP Server log directory (available only when running as root, path `/var/log/httpd` is used in case of Fedora based image) |
|
||||
|
||||
**Notice: When mouting a directory from the host into the container, ensure that the mounted
|
||||
directory has the appropriate permissions and that the owner and group of the directory
|
||||
matches the user UID or name which is running inside the container.**
|
||||
|
||||
|
||||
DEFAULT USER
|
||||
------------
|
||||
|
||||
By default, Apache HTTP Server container runs as UID 1001. That means the volume mounted directories for the files (if mounted using `-v` option) need to be prepared properly, so the UID 1001 can read them.
|
||||
|
||||
To run the container as a different UID, use `-u` option. For example if you want to run the container as UID 1234, execute the following command:
|
||||
|
||||
```
|
||||
docker run -d -u 1234 rhscl/httpd-24-rhel7
|
||||
```
|
||||
|
||||
To log into a volume mounted directory, the container needs to be run as UID 0 (see above).
|
||||
|
||||
|
||||
|
||||
TROUBLESHOOTING
|
||||
---------------
|
||||
The httpd deamon in the container logs to the standard output by default, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
docker logs <container>
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
Dockerfile and other sources for this container image are available on
|
||||
https://github.com/sclorg/httpd-container.
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
|
||||
63
root/usr/share/container-scripts/httpd/common.sh
Normal file
63
root/usr/share/container-scripts/httpd/common.sh
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Set of functions used in other scripts
|
||||
|
||||
config_general() {
|
||||
sed -i -e 's/^Listen 80/Listen 0.0.0.0:8080/' ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \
|
||||
sed -i -e '151s%AllowOverride None%AllowOverride All%' ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \
|
||||
sed -i -e 's/^Listen 443/Listen 0.0.0.0:8443/' ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
|
||||
}
|
||||
|
||||
config_log_to_stdout() {
|
||||
sed -ri " s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!g;" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
sed -ri " s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*TransferLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!g;" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf
|
||||
}
|
||||
|
||||
runs_privileged() {
|
||||
test "$(id -u)" == "0"
|
||||
return $?
|
||||
}
|
||||
|
||||
config_privileged() {
|
||||
# Change the s2i permissions back to the normal ones
|
||||
chmod 644 ${HTTPD_MAIN_CONF_PATH}/* && \
|
||||
chmod 755 ${HTTPD_MAIN_CONF_PATH} && \
|
||||
chmod 644 ${HTTPD_MAIN_CONF_D_PATH}/* && \
|
||||
chmod 755 ${HTTPD_MAIN_CONF_D_PATH} && \
|
||||
chmod 600 /etc/pki/tls/certs/localhost.crt && \
|
||||
chmod 600 /etc/pki/tls/private/localhost.key && \
|
||||
chmod 710 ${HTTPD_VAR_RUN}
|
||||
|
||||
if ! [ -v HTTPD_LOG_TO_VOLUME ] ; then
|
||||
config_log_to_stdout
|
||||
fi
|
||||
}
|
||||
|
||||
config_s2i() {
|
||||
sed -i -e "s%^DocumentRoot \"${HTTPD_DATA_ORIG_PATH}/html\"%DocumentRoot \"${HTTPD_APP_ROOT}/src\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
sed -i -e "s%^<Directory \"${HTTPD_DATA_ORIG_PATH}/html\"%<Directory \"${HTTPD_APP_ROOT}/src\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
sed -i -e "s%^<Directory \"${HTTPD_VAR_PATH}/html\"%<Directory \"${HTTPD_APP_ROOT}/src\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
echo "IncludeOptional ${HTTPD_CONFIGURATION_PATH}/*.conf" >> ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \
|
||||
head -n151 ${HTTPD_MAIN_CONF_PATH}/httpd.conf | tail -n1 | grep "AllowOverride All" || exit
|
||||
}
|
||||
|
||||
config_non_privileged() {
|
||||
sed -i -e "s/^User apache/User default/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
sed -i -e "s/^Group apache/Group root/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf
|
||||
config_log_to_stdout
|
||||
if [ -v HTTPD_LOG_TO_VOLUME ] ; then
|
||||
echo "Error: Option HTTPD_LOG_TO_VOLUME is only valid for privileged runs (as UID 0)."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Set current user in nss_wrapper
|
||||
generate_container_user() {
|
||||
local passwd_output_dir="${HTTPD_APP_ROOT}/etc"
|
||||
|
||||
export USER_ID=$(id -u)
|
||||
export GROUP_ID=$(id -g)
|
||||
envsubst < ${HTTPD_CONTAINER_SCRIPTS_PATH}/passwd.template > ${passwd_output_dir}/passwd
|
||||
export LD_PRELOAD=libnss_wrapper.so
|
||||
export NSS_WRAPPER_PASSWD=${passwd_output_dir}/passwd
|
||||
export NSS_WRAPPER_GROUP=/etc/group
|
||||
}
|
||||
|
||||
15
root/usr/share/container-scripts/httpd/passwd.template
Normal file
15
root/usr/share/container-scripts/httpd/passwd.template
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
root:x:0:0:root:/root:/bin/bash
|
||||
bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
daemon:x:2:2:daemon:/sbin:/sbin/nologin
|
||||
adm:x:3:4:adm:/var/adm:/sbin/nologin
|
||||
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
|
||||
sync:x:5:0:sync:/sbin:/bin/sync
|
||||
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
|
||||
halt:x:7:0:halt:/sbin:/sbin/halt
|
||||
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
|
||||
operator:x:11:0:operator:/root:/sbin/nologin
|
||||
games:x:12:100:games:/usr/games:/sbin/nologin
|
||||
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
|
||||
nobody:x:99:99:Nobody:/:/sbin/nologin
|
||||
default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin
|
||||
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
|
||||
31
s2i/bin/assemble
Executable file
31
s2i/bin/assemble
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh
|
||||
|
||||
echo "---> Enabling s2i support in httpd24 image"
|
||||
|
||||
config_s2i
|
||||
|
||||
echo "---> Installing application source"
|
||||
cp -Rf /tmp/src/. ./
|
||||
|
||||
if [ -d ./httpd-cfg ]; then
|
||||
echo "---> Copying httpd configuration files..."
|
||||
if [ "$(ls -A ./httpd-cfg/*.conf)" ]; then
|
||||
cp -v ./httpd-cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"
|
||||
rm -rf ./httpd-cfg
|
||||
fi
|
||||
else
|
||||
if [ -d ./cfg ]; then
|
||||
echo "---> Copying httpd configuration files from deprecated './cfg' directory, use './httpd-cfg' instead..."
|
||||
if [ "$(ls -A ./cfg/*.conf)" ]; then
|
||||
cp -v ./cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"
|
||||
rm -rf ./cfg
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fix source directory permissions
|
||||
fix-permissions ./
|
||||
7
s2i/bin/run
Executable file
7
s2i/bin/run
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh
|
||||
|
||||
export HTTPD_RUN_BY_S2I=1
|
||||
|
||||
run-httpd $@
|
||||
17
s2i/bin/usage
Executable file
17
s2i/bin/usage
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'`
|
||||
NAMESPACE=centos
|
||||
[[ $DISTRO =~ rhel* ]] && NAMESPACE=rhscl
|
||||
|
||||
cat <<EOF
|
||||
This is a S2I ${IMAGE_DESCRIPTION} ${DISTRO} base image:
|
||||
To use it, install S2I: https://github.com/openshift/source-to-image
|
||||
|
||||
Sample invocation:
|
||||
|
||||
s2i build https://github.com/sclorg/httpd-container.git --context-dir=2.4/test/sample-test-app/ ${NAMESPACE}/httpd-24-${DISTRO}7 httpd-sample-app
|
||||
|
||||
You can then run the resulting image via:
|
||||
docker run -p 8080:8080 httpd-sample-app
|
||||
EOF
|
||||
0
sources
Normal file
0
sources
Normal file
239
test/run
Executable file
239
test/run
Executable file
|
|
@ -0,0 +1,239 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
IMAGE_NAME="${IMAGE_NAME:-rhscl/httpd-24-rhel7}"
|
||||
|
||||
THISDIR=$(dirname ${BASH_SOURCE[0]})
|
||||
. ${THISDIR}/utils.sh
|
||||
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
|
||||
|
||||
function _container_is_scl() {
|
||||
docker inspect --format='{{.Config.Env}}' "${1-$IMAGE_NAME}" | grep -q HTTPD_SCL
|
||||
return $?
|
||||
}
|
||||
|
||||
function create_container() {
|
||||
local name="$1" ; shift
|
||||
local image="${1-$IMAGE_NAME}"
|
||||
[ -n "$1" ] && shift
|
||||
cidfile="$CIDFILE_DIR/$name"
|
||||
# create container with a cidfile in a directory for cleanup
|
||||
docker run ${DOCKER_ARGS:-} --cidfile $cidfile -d $image || return 1
|
||||
echo docker run ${DOCKER_ARGS:-} --cidfile $cidfile -d $image
|
||||
echo "Created container $(cat $cidfile)"
|
||||
}
|
||||
|
||||
function update_overall() {
|
||||
res="$1"
|
||||
if [ "$res" != 0 ]; then
|
||||
overall="$res"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_cid() {
|
||||
local id="$1" ; shift || return 1
|
||||
echo $(cat "$CIDFILE_DIR/$id")
|
||||
}
|
||||
|
||||
function get_container_ip() {
|
||||
local id="$1" ; shift
|
||||
docker inspect --format='{{.NetworkSettings.IPAddress}}' $(get_cid "$id")
|
||||
}
|
||||
|
||||
function rm_container() {
|
||||
local name="$1"
|
||||
local cid="`get_cid $name`"
|
||||
docker kill "$cid" || :
|
||||
docker rm "$cid"
|
||||
rm -f "$CIDFILE_DIR/$name"
|
||||
}
|
||||
|
||||
function run() {
|
||||
cmd="$1"
|
||||
expected_res="${2:-0}"
|
||||
msg="${3:-Running command '$cmd'}"
|
||||
set +e
|
||||
run_command "$cmd" "$expected_res" "$msg"
|
||||
res=$?
|
||||
set -e
|
||||
test "$res" -eq "$expected_res" && res=0 || res=1
|
||||
update_overall $res
|
||||
return $res
|
||||
}
|
||||
|
||||
|
||||
function _check_test_page() {
|
||||
run "curl ${1}:8080 > output"
|
||||
if ! run "fgrep -e 'Test Page for the Apache HTTP Server on' output" ; then
|
||||
cat output
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function run_default_page_test() {
|
||||
# Check default page
|
||||
run "create_container test_default_page"
|
||||
sleep 2
|
||||
cip=$(get_container_ip 'test_default_page')
|
||||
_check_test_page ${cip}
|
||||
}
|
||||
|
||||
function run_as_root_test() {
|
||||
# Try running as root
|
||||
DOCKER_ARGS="-u 0"
|
||||
run "create_container test_run_as_root"
|
||||
DOCKER_ARGS=
|
||||
sleep 2
|
||||
cip=$(get_container_ip 'test_run_as_root')
|
||||
_check_test_page ${cip}
|
||||
}
|
||||
|
||||
|
||||
function run_log_to_volume_test() {
|
||||
_run_invalid_log_volume_test
|
||||
if _container_is_scl ; then
|
||||
_run_log_to_volume_test old /var/log/httpd24
|
||||
else
|
||||
_run_log_to_volume_test new /var/log/httpd
|
||||
fi
|
||||
}
|
||||
|
||||
function _run_log_to_volume_test() {
|
||||
# Check the HTTP_LOG_TO_VOLUME env variable
|
||||
local variant=${1}
|
||||
local volume_dir=${2}
|
||||
local logs_dir=$(mktemp -d /tmp/httpd-test-volume-XXXXXX)
|
||||
run "ls -d ${logs_dir} || mkdir ${logs_dir}" 0 'Create log directory'
|
||||
run "chown -R 1001:1001 ${logs_dir}"
|
||||
run "chcon -Rvt svirt_sandbox_file_t ${logs_dir}" 0 'Change SELinux context on the log dir'
|
||||
DOCKER_ARGS="-e HTTPD_LOG_TO_VOLUME=1 -u 0 -v ${logs_dir}:${volume_dir}"
|
||||
run "create_container test_log_dir_${variant}"
|
||||
DOCKER_ARGS=
|
||||
sleep 2
|
||||
cip=$(get_container_ip "test_log_dir_${variant}")
|
||||
run "curl ${cip}:8080 > /dev/null"
|
||||
ls ${logs_dir} > output
|
||||
run "grep -e '^access_log$' output" 0 "Checking that file access_log exists"
|
||||
run "grep -e '^error_log$' output" 0 "Checking that file error_log exists"
|
||||
run "grep -e '^ssl_access_log$' output" 0 "Checking that file ssl_access_log exists"
|
||||
run "grep -e '^ssl_error_log$' output" 0 "Checking that file ssl_error_log exists"
|
||||
run "grep -e '^ssl_request_log$' output" 0 "Checking that file ssl_request_log exists"
|
||||
}
|
||||
|
||||
function _run_invalid_log_volume_test() {
|
||||
# Check wrong usage of the HTTP_LOG_TO_VOLUME env variable
|
||||
DOCKER_ARGS="-e HTTPD_LOG_TO_VOLUME=1 -u 1001"
|
||||
run "create_container test_log_dir_fail"
|
||||
DOCKER_ARGS=
|
||||
sleep 2
|
||||
cid=$(get_cid "test_log_dir_fail")
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' ${cid})
|
||||
run "test $exit_status == 1" 0 "Checking that setting HTTPD_LOG_TO_VOLUME is not allowed if UID is not 0"
|
||||
}
|
||||
|
||||
|
||||
function run_data_volume_test() {
|
||||
if _container_is_scl ; then
|
||||
_run_data_volume_test old /opt/rh/httpd24/root/var/www
|
||||
fi
|
||||
_run_data_volume_test new /var/www
|
||||
}
|
||||
|
||||
function _run_data_volume_test() {
|
||||
local variant=${1}
|
||||
local volume_dir=${2}
|
||||
# Test that docker volume for DocumentRoot works
|
||||
datadir=$(mktemp -d /tmp/httpd-test-data-XXXXXX)
|
||||
run "mkdir -p ${datadir}/html" 0 'Create document root'
|
||||
run "echo hello > ${datadir}/html/index.html"
|
||||
run "chown -R 1001:1001 ${datadir}"
|
||||
run "chcon -Rvt svirt_sandbox_file_t ${datadir}/" 0 'Change SELinux context on the document root'
|
||||
DOCKER_ARGS="-v ${datadir}:${volume_dir}"
|
||||
run "create_container test_doc_root_${variant}"
|
||||
DOCKER_ARGS=
|
||||
sleep 2
|
||||
cip=$(get_container_ip "test_doc_root_${variant}")
|
||||
run "curl ${cip}:8080 > output"
|
||||
run "grep -e '^hello$' output"
|
||||
}
|
||||
|
||||
|
||||
function run_s2i_test() {
|
||||
# Test s2i use case
|
||||
# Since we built the candidate image locally, we don't want S2I attempt to pull
|
||||
# it from Docker hub
|
||||
s2i_args="--force-pull=false"
|
||||
run "s2i usage ${s2i_args} ${IMAGE_NAME}" 0 "Testing 's2i usage'"
|
||||
run "s2i build ${s2i_args} file://${test_dir}/sample-test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp" 0 "Testing 's2i build'"
|
||||
DOCKER_ARGS='-u 1000'
|
||||
create_container testing-app-s2i ${IMAGE_NAME}-testapp
|
||||
DOCKER_ARGS=
|
||||
sleep 5
|
||||
cip=$(get_container_ip 'testing-app-s2i')
|
||||
run "curl ${cip}:8080 > output_s2i"
|
||||
run "fgrep -e 'This is a sample s2i application with static content.' output_s2i"
|
||||
# 0 "Checking page served by s2i feature"
|
||||
sleep 2
|
||||
}
|
||||
|
||||
|
||||
function run_all_tests() {
|
||||
for test_case in $TEST_LIST; do
|
||||
: "Running test $test_case"
|
||||
$test_case
|
||||
done;
|
||||
}
|
||||
|
||||
|
||||
function cleanup() {
|
||||
for cidfile in $CIDFILE_DIR/* ; do
|
||||
CONTAINER=$(cat $cidfile)
|
||||
|
||||
echo "Stopping and removing container $CONTAINER..."
|
||||
docker stop $CONTAINER
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' $CONTAINER)
|
||||
if [ "$exit_status" != "0" ]; then
|
||||
echo "Dumping logs for $CONTAINER"
|
||||
docker logs $CONTAINER
|
||||
fi
|
||||
docker rm $CONTAINER
|
||||
rm $cidfile
|
||||
echo "Done."
|
||||
done
|
||||
if [ "$overall" -eq 0 ] ; then
|
||||
print_result "pass" "All tests passed."
|
||||
else
|
||||
print_result "fail" "Tests failed."
|
||||
fi
|
||||
rmdir $CIDFILE_DIR
|
||||
rm -Rf "$working_dir"
|
||||
return "$overall"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
|
||||
working_dir=`mktemp -d`
|
||||
pushd $working_dir > /dev/null || exit 1
|
||||
|
||||
CIDFILE_DIR=`pwd`/cid_files
|
||||
mkdir "$CIDFILE_DIR"
|
||||
|
||||
overall=0
|
||||
|
||||
run "docker inspect $IMAGE_NAME >/dev/null || docker pull $IMAGE_NAME" 0
|
||||
|
||||
|
||||
TEST_LIST="\
|
||||
run_default_page_test
|
||||
run_as_root_test
|
||||
run_log_to_volume_test
|
||||
run_data_volume_test
|
||||
run_s2i_test"
|
||||
|
||||
test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0
|
||||
|
||||
TEST_LIST=${@:-$TEST_LIST} run_all_tests
|
||||
|
||||
popd > /dev/null
|
||||
|
||||
exit "$overall"
|
||||
1
test/sample-test-app/index.html
Normal file
1
test/sample-test-app/index.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
This is a sample s2i application with static content.
|
||||
46
test/utils.sh
Executable file
46
test/utils.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function print_result {
|
||||
local RESET='\e[0m'
|
||||
local RED='\e[0;31m'
|
||||
local GREEN='\e[0;32m'
|
||||
local YELLOW='\e[1;33m'
|
||||
local PASS="${RESET}${GREEN}[PASS]"
|
||||
local FAIL="${RESET}${RED}[FAIL]"
|
||||
local WORKING="${RESET}${YELLOW}[....]"
|
||||
local STATUS="$1"
|
||||
shift
|
||||
|
||||
if [ "${STATUS}" = pass ]; then
|
||||
echo -en "${PASS}"
|
||||
elif [ "${STATUS}" = fail ]; then
|
||||
echo -en "${FAIL}"
|
||||
elif [ "${STATUS}" = working ]; then
|
||||
echo -en "${WORKING}"
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
echo -en " ${@}${RESET}"
|
||||
echo
|
||||
}
|
||||
|
||||
function get_status {
|
||||
if [ "$1" = "$2" ]; then
|
||||
echo pass
|
||||
else
|
||||
echo fail
|
||||
fi
|
||||
}
|
||||
|
||||
function run_command {
|
||||
local cmd="$1"
|
||||
local expected="${2:-0}"
|
||||
local msg="${3:-Running command '$cmd'}"
|
||||
print_result working "$msg"
|
||||
eval $cmd
|
||||
local res="$?"
|
||||
status=`get_status "$res" "$expected"`
|
||||
print_result "$status" "$msg"
|
||||
return "$res"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue