SHARE
TWEET

Untitled

a guest Apr 2nd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @api_view(['GET'])
  2. def docker_api(request):
  3.     # declare variables
  4.     # instance
  5.     name_comapny = "instance_one"
  6.     instance_odoo = name_comapny+"_odoo"
  7.     instance_db = name_comapny+"_db"
  8.     instance_network = name_comapny+"_default"
  9.     # db & odoo env vars
  10.     POSTGRES_TCP_ADDR = "db"
  11.     POSTGRES_TP_PORT = "5432"
  12.     PGDATA="/var/lib/postgresql/data/pgdata"
  13.     POSTGRES_PASSWORD = "odoo"
  14.     POSTGRES_USER = "odoo"
  15.  
  16.     client = docker.APIClient(base_url='unix://var/run/docker.sock')
  17.    
  18.     # create network for the new odoo instance
  19.     net_id = client.create_network(
  20.         instance_network, driver=None, options=None, ipam=None,
  21.         check_duplicate=None, internal=False, labels=None,
  22.         enable_ipv6=False, attachable=None, scope=None, ingress=None
  23.     )
  24.  
  25.     # create db - postgres container
  26.     container_db = client.create_container(
  27.         "postgres:10",
  28.         name=instance_db,
  29.         host_config=client.create_host_config(
  30.             network_mode=instance_network
  31.         ),
  32.         environment={
  33.             "POSTGRES_PASSWORD":POSTGRES_PASSWORD,
  34.             "POSTGRES_USER":POSTGRES_USER,
  35.             "PGDATA":PGDATA
  36.         },
  37.         volumes=[PGDATA]
  38.     )
  39.  
  40.     # create odoo container
  41.     container_odoo = client.create_container(
  42.         "odoo:11.0",
  43.         ports=[8069],
  44.         name=instance_odoo,
  45.         host_config=client.create_host_config(
  46.             port_bindings={
  47.                 8069:8067
  48.             },
  49.             network_mode=instance_network,
  50.             links={instance_db:'db'}
  51.         ),
  52.         environment={
  53.             "POSTGRES_TCP_ADDR":POSTGRES_TCP_ADDR,
  54.             "POSTGRES_TP_PORT":POSTGRES_TP_PORT,
  55.             "POSTGRES_PASSWORD":POSTGRES_PASSWORD,
  56.             "POSTGRES_USER":POSTGRES_USER
  57.         }
  58.     )
  59.    
  60.     cs = client.containers()
  61.        
  62.     return JsonResponse({'res':cs})
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top