Sign inSign up

senaddizdarevic/docker-compose-api

By senaddizdarevic

•Updated about 2 years ago

Simplifying Docker Host Management with DockerComposeAPI

Image
API management
Developer tools
0

391

senaddizdarevic/docker-compose-api repository overview

⁠docker-compose-api DockerComposeAPI

This application is designed to interact with docker-compose commands using RESTful APIs. It allows users to run docker-compose commands, and view the output.

⁠Architecture
  • Flask API: The API provides endpoints for interacting with docker-compose commands.
  • Gunicorn: The Flask application runs behind Gunicorn, a Python WSGI server.
  • Nginx: Nginx acts as a reverse proxy server, routing incoming requests to the Gunicorn server.

diagram

⁠Running the Application

To run the application, follow these steps:

  1. Pill the Docker image:

    docker pull senaddizdarevic/docker-compose-api:latest
    
  2. Create docker-compose.yaml:

    services:
      api:
        image: senaddizdarevic/docker-compose-api:latest
        container_name: docker_compose_api
        ports:
          - "8080:80"
        env_file:
          - .env
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock:ro
          - ./test:/app/source/ #Add your docker-compose.yml source directory here.
    

    Create .env file for storing variables.

    MY_JWT_SECRET_KEY=your_default_jwt_secret_key # Create JWT secret key woth SSL command (openssl rand -hex 32)
    API_USERNAME=admin
    API_PASSWORD=password
    
  3. Run the Docker container in detached mode:

    docker compose up -d
    
⁠API Endpoints

The application provides the following endpoints:

  • POST /login: Authenticate with a username and password (admin/password).
  • POST /runcmd: Run a docker-compose command. The command must start with docker-compose.
⁠Example usage:
# Obtain JWT token
TOKEN=$(curl -X POST http://localhost:8080/login \
             -H "Content-Type: application/json" \
             -d '{"username": "admin", "password": "password"}' | jq -r .access_token)

# Run a docker-compose command
curl -X POST http://localhost:8080/runcmd \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer $TOKEN" \
     -d '{"command":"docker-compose -f source/docker-compose.yml up -d"}'
⁠Additional Information
  • Logging: Logs can be accessed through Docker logs for debugging and monitoring.

    Gunicorn log

    docker logs docker_compose_api
    

    Flask log

    docker exec -it docker_compose_api cat /app/api.log
    

    Nginx logs

    docker exec -it docker_compose_api cat /var/log/nginx/access.log
    
    docker exec -it docker_compose_api cat /var/log/nginx/error.log
    

For more details, please refer to the official DockerComposeAPI documentation⁠.

Tag summary

Content type

Image

Digest

sha256:d4f13ff70…

Size

152.9 MB

Last updated

about 2 years ago

docker pull senaddizdarevic/docker-compose-api