This is a Dockerized Flask API that simulates the status of a rocket on its journey to the moon. The rocket can be in one of four states: "On Earth", "In transit", "On the moon", or "LOS (loss of signal)". The API returns a random status along with additional information based on the state.
rocket_status_api/
│
├── app/
│ ├── __init__.py
│ ├── routes.py
│ └── status.py
├── Dockerfile
├── requirements.txt
└── app.py
Ensure you have the following installed on your local machine:
- Docker
- Docker Compose (optional, if you plan to use Docker Compose)
-
Clone the repository:
git clone <repository_url> cd rocket_status_api
-
Build the Docker image:
docker build -t rocket_status_api .
To run the Docker container and expose the API on port 5001:
docker run -d -p 5001:5000 rocket_status_api
Once the container is running, you can access the API at:
http://localhost:5001/status
To check the status of the rocket, you can use a web browser or a tool like curl
:
curl http://localhost:5001/status
To stop the running container, you can use the docker ps
command to find the container ID and then docker stop
to stop it:
-
List all running containers:
docker ps
-
Stop the container:
docker stop <container_id>
The API returns a JSON response with the status of the rocket. Example responses include:
-
On Earth:
{ "state": "On Earth" }
-
In transit:
{ "state": "In transit", "distance_from_earth": "150000 km", "distance_to_moon": "50000 km", "speed": "20000 km/h" }
-
On the moon:
{ "state": "On the moon", "nearest_crater": "Tycho", "landing_time": "2023-06-01 12:34:56" }
-
LOS (loss of signal):
{ "state": "LOS" }
To run the Flask application locally without Docker, follow these steps:
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Run the Flask application:
python app.py
The application will be accessible at http://localhost:5000/status
.