This repository contains a Dockerfile and a Python script (server.py) to run a simple HTTP server that returns the current time in Toronto as JSON for GET requests. The server is built using Python 3.11 and is dockerized for easy deployment.
To build and run the Docker container: Ensure you have Docker installed on your system. Clone this repository to your local machine. Navigate to the root directory of the repository. Building the Docker Image To build the Docker image, run the following command:
docker build -t toronto-time-server .
Once the image is built, you can run the Docker container using the following command:
docker run -d -p 8010:8010 toronto-time-server
This will start the HTTP server inside the container, listening on port 8010. You can access the server at http://localhost:8010.
Usage Once the server is running, you can send GET requests to http://localhost:8010 to retrieve the current time in Toronto in JSON format.
curl http://localhost:8010
{
"TorontoTime": "2024-02-15 12:00:00"
}
The server is implemented using Python's built-in http.server module. It creates a simple HTTP server that handles GET requests by returning the current time in Toronto timezone as JSON.
The logic for calculating the Toronto time is done by subtracting 5 hours from the current UTC time.
Dockerfile: Defines the Docker image for the server. server.py: Contains the implementation of the HTTP server. README.md: This file.
Contributions to improve or extend this project are welcome! If you encounter any issues or have suggestions for enhancements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.