Code Monkey home page Code Monkey logo

spin-docker-container-service's Introduction

SPIN DOCKER CONTAINER SERVICE

Ruby REST API for spining up multiple containers of any type on single server mapping each container to subdomain using nginx-proxy container.

I have used it to run my all applications on single server mapping each one to subdomain on testing environment - saving me cost.

Prerequisites

You will need the following things properly installed and runningon your computer

Nginx Proxy

  • docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
  • for SSL docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

Installation

  • git clone <repository-url> this repository
  • change into the new directory
  • sudo gem install bundler
  • bundle install

Running / Development

You will need the following environments variables

  • export SPIN_DOCKER_CONTAINER_SERVICE_DOMAIN=localhost/yourdomain.com
  • export SPIN_DOCKER_CONTAINER_SERVICE_ROOT_PATH=/Users/pradeepjaiswar/workspace/apps This is where all your repos wil get cloned

Uses

  • rerun 'rackup -p 3000' or rerun 'rackup -p 3000'
  • don't run on port 80 as nginx-proxy should be running on port 80

Visit http://localhost:3000/

Uses on Production

  • sudo -E rackup -p 9000
  • setup nginx proxy pass to port 9000
  • don't run on port 443 as nginx-proxy should be running on port 443

REST API

For spinnig up new container

POST /containers with below HEADERS

container_image_name
github_repo_url 
mount_to_path
container_expose_port
container_startup_command
  • container_image_name :: Docker hub image name for source code
  • github_repo_url :: Repo url for source code. This can be url of any hosting service for version control using git. bitbucket , gitlab etc.
  • mount_to_path :: Path where source code should be mounted in container
  • container_expose_port :: Container port which will be mapped to subdomain
  • container_startup_command :: Command to run inside container when it's start. This can be command to start your application or application setup command

Update the source code of running containers

PATCH /containers with below HEADERS

github_repo_url
branch_name
  • github_repo_url :: Repo url for source code
  • branch_name :: Change the branch. Default is master

Kill containers

DELETE /containers with below HEADERS

github_repo_url
  • github_repo_url :: Repo url for source code. Because container name is MD5 of github_repo_url.

Kill long running containers

DELETE /containers with below HEADERS

 container_image_name
 hours
 days
  • container_image_name :: Name of image whose child container should be kill
  • hours :: Container running more than specified hours will get killed
  • days :: Container running more than specified days will get killed

Example for spinning up python notebook

POST /containers with below HEADERS

container_image_name :: mado023/greyatom-jupyter
github_repo_url :: https://github.com/commit-live-students/linear_regression_project
mount_to_path :: /home/notebooks
container_expose_port :: 8888
container_startup_command :: /opt/conda/bin/jupyter notebook --notebook-dir=/home/notebooks --ip='*'  --port=8888 --no-browser --allow-root

spin-docker-container-service's People

Contributors

pradeepjaiswar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.