Go API Docker Image Help Document Overview This Docker image provides a Go API that accepts shell commands via a POST method and returns the output. It is based on AWS Linux and includes proper error handling. This document will guide you through pulling the image, running the container, and using the API.
Prerequisites Docker installed on your machine Internet connection to pull the Docker image from Docker Hub Pulling the Docker Image To pull the Docker image from Docker Hub, run the following command:
docker pull abhiimages/goapi:v1
Running the Docker Container To run the Docker container, execute the following command:
docker run -d -p 8080:8080 abhiimages/goapi:v1
This command will start the Go API server and map port 8080 on your local machine to port 8080 in the container.
Using the Go API The Go API accepts POST requests at the /execute endpoint. The request should include a JSON payload with the shell command to be executed.
Example Request To execute a shell command, use the following curl command:
curl -X POST -H "Content-Type: application/json" -d '{"command": "{"command name"}' http://{Your Base os Ip}:8080/execute
Example Response The response will be in JSON format, containing the output of the command and any errors if they occurred. For example:
json Copy code { "output": "total 8\ndrwxr-xr-x 2 root root 4096 Aug 6 10:00 bin\ndrwxr-xr-x 2 root root 4096 Aug 6 10:00 etc\n", "error": "" } If an error occurs during the execution of the command, the response will include the error message:
json Copy code { "output": "", "error": "sh: invalidcommand: command not found\n" } Error Handling The API handles errors gracefully. If an invalid command is provided, the error message will be included in the response. If the JSON payload is malformed, a 400 Bad Request status will be returned with an error message.
Customizing the Go API If you need to customize the Go API, you can modify the main.go file. The source code for the Go API is included in the Docker image. To make changes:
Pull the Docker image as described above. Run the container with a volume mount to your local directory where you have the modified main.go file:
docker exec -it container name bash
Conclusion This Docker image provides a convenient way to execute shell commands via a Go API. It is easy to set up and use. For any further questions or issues, please contact [Your Contact Information].
Feel free to adjust this document based on your specific requirements and details.
Content type
Image
Digest
sha256:37c18526d…
Size
330.2 MB
Last updated
about 2 years ago
docker pull abhiimages/goapi:v1