A simple HTTP server build with TypeScript and Deno as a runtime to serve a simple JSON response. This is for Docker's Deno Language Guide.
The server only supports the HTTP GET method at the moment. When a GET request is received, the server responds with a JSON object:
{
"message": "OK"
}
Below is the Dockerfile for the our server:
# Use the official Deno image
FROM denoland/deno:latest
# Set the working directory
WORKDIR /app
# Copy server code into the container
COPY server.ts .
# Set permissions (optional but recommended for security)
USER deno
# Expose port 8000
EXPOSE 8000
# Run the Deno server
CMD ["run", "--allow-net", "server.ts"]
To run this application using Docker Compose, you'll need to create a compose.yml
file.
Here's the compose.yml
file:
services:
server:
image: deno-server
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
To build and run the Docker image using Docker Compose, use the following command:
docker compose up
This will build the Docker image and then run it, mapping the container's port 3000 to port 3000 on the host machine. You can then access the API by visiting http://localhost:3000
in your web browser.
Any feedback and contributions are welcome! Please open an issue before submitting a pull request.