The exact steps depend on the base image of your Docker container and which Linux distribution you’re using. Below are two common examples: one for a CentOS‑ or RHEL‑based image and one for a Debian/Ubuntu‑based image.
For a CentOS‑/RHEL‑Based Image
-
Modify Your Dockerfile
Add a line to update the package index and install mod_ssl. For example:
FROM centos:7
# Update packages and install Apache HTTP Server and mod_ssl
RUN yum -y update && \
yum -y install httpd mod_ssl && \
yum clean all
# Expose necessary ports (80 and 443 are typical for http and https)
EXPOSE 80 443
# Copy your configuration files (if any)
COPY your-httpd.conf /etc/httpd/conf/httpd.conf
# Set the entrypoint to start Apache in the foreground
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
-
Build and Run Your Docker Image
docker build -t my-centos-apache .
docker run -d -p 80:80 -p 443:443 my-centos-apache
The package mod_ssl is available from the default repositories, and installing it will drop in a default SSL configuration file (typically in /etc/httpd/conf.d/ssl.conf) that you can modify if needed.
For a Debian/Ubuntu‑Based Image
On Debian or Ubuntu, the Apache package already includes the SSL module. You need to enable it using the a2enmod command.
-
Modify Your Dockerfile
FROM ubuntu:20.04
# Prevent interactive installation
ENV DEBIAN_FRONTEND=noninteractive
# Update packages and install Apache2
RUN apt-get update && \
apt-get install -y apache2 && \
apt-get clean
# Enable the SSL module and the default SSL site configuration
RUN a2enmod ssl && a2ensite default-ssl && \
service apache2 reload
# Expose the relevant ports
EXPOSE 80 443
# Copy your configuration files (if any)
COPY your-apache-config.conf /etc/apache2/sites-available/your-apache-config.conf
# Optionally, disable the default site if you have another configuration
# RUN a2dissite 000-default
# Start Apache in the foreground
CMD ["apachectl", "-D", "FOREGROUND"]
-
Build and Run Your Docker Image
docker build -t my-ubuntu-apache .
docker run -d -p 80:80 -p 443:443 my-ubuntu-apache
In this case, the SSL module is bundled with Apache2, so you just need to enable it. The command a2enmod ssl sets up the module, and a2ensite default-ssl activates the default SSL virtual host configuration (usually found at /etc/apache2/sites-available/default-ssl.conf).
Final Notes
- Configuration Files:
Make sure to adjust your SSL configuration files (like certificate paths, ciphers, etc.) for your environment.
- Ports:
Ensure that your SSL port (typically 443) is exposed and mapped correctly when running the container.
- Security:
Verify that you have valid SSL certificates or use self-signed certificates for testing purposes.
By following these instructions based on your base image, you will have mod_ssl (or the equivalent in the case of Debian/Ubuntu) installed and enabled in your Docker container.