-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDjango-Docker-NC.py
More file actions
23 lines (20 loc) · 831 Bytes
/
Django-Docker-NC.py
File metadata and controls
23 lines (20 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.views.generic import View
from django.shortcuts import HttpResponse
import socket
import docker
dport = 8080
def checkport( port ):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1',port))
while((result) == 0):
port = port + 1
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1',port))
return port
class TestView(View):
def get(self, request, *args, **kwargs):
open_port = checkport(dport)
client = docker.from_env()
opstr = "Nextcloud instance started on Port Number # " + str(open_port)
container = client.containers.run("nextcloud:latest", ports={80:open_port}, detach=True)
return HttpResponse(opstr)