This project creates a simple HTTPS server using Python and Docker. It includes a self-signed certificate generated using OpenSSL and serves files over HTTPS from port 8400. It also contains a 35 MB "big file" filled with random data.
certs/: Contains themkcert.shscript to generate self-signed certificates.https_server.py: A Python script that runs the HTTPS server usinghttp.serverandssl.Dockerfile: Docker configuration to build the image.Makefile: Automates the build, run, and push process using Make.README.md: Instructions on how to use the project.
- Docker installed on your machine.
- Make installed on your machine.
-
Generate SSL Certificates:
Run the following command to generate the SSL certificates using the
certs/mkcert.shscript:make certs
This will generate the
server.crtandserver.keyfiles. -
Build the Docker Image:
Build the Docker image using the
Makefile:make docker-build
This builds the Docker image named test-https-server.
-
Run the Docker Container:
Start the HTTPS server using the built Docker image:
make run
The server will start and listen on port 8400. You can access the server at https://localhost:8400.
Note: Since a self-signed certificate is used, your browser will show a security warning. You can bypass this warning to proceed to the site.
-
Stop the Docker Container:
To stop the running container:
make stop
-
Push the Docker Image to Docker Hub:
To push the Docker image to Docker Hub, you need to set the DOCKER_USERNAME in the Makefile. After that, push the image:
make docker-push
Ensure you are logged into Docker Hub before running this command:
docker login
-
Clean Up:
To clean up the generated certificates, stop the running container, and remove the Docker image:
make clean
The Docker container uses a volume at /usr/src/app. This volume ensures that the files inside the container (e.g., large files and certificates) persist, even if the container is stopped.
To mount a specific host directory as the volume, you can run:
docker run -d -p 8400:8400 -p 80:80 -v /path/to/host/directory:/usr/src/app/www --name test_https_server test-https-serverThis will mount the host directory /path/to/host/directory to /usr/src/app/www inside the container.
To measure download speed from container, you can run:
curl -k https://localhost:8400/large_test_file.txt -w '\nResponse size:\t%{size_download} bytes\nDownload speed:\t%{speed_download} bps\nTotal Time:\t%{time_total} s\n' -o /dev/null- Certificate Warnings: Since a self-signed certificate is used, your browser or client may show a security warning. This is expected in a development environment.
- Permissions Issues: Ensure the
mkcert.shscript is executable by runningchmod +x certs/mkcert.sh.
Dockerfilenow includes aVOLUMEdirective to persist the app's working directory.README.mdprovides detailed instructions for building, running, and pushing the image, along with usage of the volume and handling common issues.
This should cover the entire workflow from generating certificates to pushing the image to a Docker registry.