fixed allocating extra ports
This commit is contained in:
@@ -45,6 +45,10 @@ func PrintStartContainer(d *docker.DockerVM){
|
|||||||
fmt.Println("SSH password: " + fmt.Sprint(d.SSHPassword))
|
fmt.Println("SSH password: " + fmt.Sprint(d.SSHPassword))
|
||||||
fmt.Println("VNC port: " + fmt.Sprint(d.VNCPort))
|
fmt.Println("VNC port: " + fmt.Sprint(d.VNCPort))
|
||||||
fmt.Println("VNC password: " + fmt.Sprint(d.VNCPassword))
|
fmt.Println("VNC password: " + fmt.Sprint(d.VNCPassword))
|
||||||
|
fmt.Println("Ports Open")
|
||||||
|
for i := range d.Ports {
|
||||||
|
fmt.Println(d.Ports[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
p2p-rendering-computation
Executable file
BIN
p2p-rendering-computation
Executable file
Binary file not shown.
@@ -56,7 +56,6 @@ func BuildRunContainer(NumPorts int) (*DockerVM,error) {
|
|||||||
for i := 2; i < count; i++ {
|
for i := 2; i < count; i++ {
|
||||||
RespDocker.Ports = append(RespDocker.Ports, Ports[i])
|
RespDocker.Ports = append(RespDocker.Ports, Ports[i])
|
||||||
}
|
}
|
||||||
//fmt.Println(Ports[0])
|
|
||||||
|
|
||||||
// Sets Free port to Struct
|
// Sets Free port to Struct
|
||||||
RespDocker.SSHPort = Ports[0]
|
RespDocker.SSHPort = Ports[0]
|
||||||
@@ -66,7 +65,6 @@ func BuildRunContainer(NumPorts int) (*DockerVM,error) {
|
|||||||
RespDocker.SSHUsername = "master"
|
RespDocker.SSHUsername = "master"
|
||||||
RespDocker.SSHPassword = "password"
|
RespDocker.SSHPassword = "password"
|
||||||
RespDocker.VNCPassword = "vncpassword"
|
RespDocker.VNCPassword = "vncpassword"
|
||||||
RespDocker.Ports = Ports
|
|
||||||
|
|
||||||
//Default parameters
|
//Default parameters
|
||||||
RespDocker.TagName = "p2p-ubuntu"
|
RespDocker.TagName = "p2p-ubuntu"
|
||||||
@@ -127,14 +125,18 @@ func (d *DockerVM)imageBuild(dockerClient *client.Client) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Starts container and assigns port numbers
|
// Starts container and assigns port numbers
|
||||||
|
// Sample Docker run Command
|
||||||
|
// docker run -d=true --name=Test123 --restart=always -p 3443:6901 -p 3453:22
|
||||||
|
//-p 3434:3434 -p 3245:3245 -v=/opt/data:/data p2p-ubuntu /start > /dev/null
|
||||||
func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*2000)
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*2000)
|
||||||
|
|
||||||
|
//Exposed ports for docker config file
|
||||||
|
var ExposedPort nat.PortSet
|
||||||
|
|
||||||
config := &container.Config{
|
ExposedPort = nat.PortSet{
|
||||||
Image : d.TagName,
|
"22/tcp": struct{}{},
|
||||||
Entrypoint: [] string {"/dockerstartup/vnc_startup.sh","/start"},
|
"6901/tcp": struct{}{},
|
||||||
Volumes: map[string]struct{}{"/opt/data:/data":{}},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Port forwarding for VNC and SSH ports
|
// Port forwarding for VNC and SSH ports
|
||||||
@@ -153,14 +155,16 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opening other ports (At the current moment only TCP ports can be
|
|
||||||
// opened
|
|
||||||
for i := range d.Ports {
|
for i := range d.Ports {
|
||||||
|
|
||||||
Port, err := nat.NewPort("tcp",fmt.Sprint(d.Ports[i]))
|
Port, err := nat.NewPort("tcp",fmt.Sprint(d.Ports[i]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exposed Ports
|
||||||
|
ExposedPort[Port] = struct{}{}
|
||||||
|
|
||||||
PortForwarding[Port] = []nat.PortBinding{
|
PortForwarding[Port] = []nat.PortBinding{
|
||||||
{
|
{
|
||||||
HostIP: "0.0.0.0",
|
HostIP: "0.0.0.0",
|
||||||
@@ -169,6 +173,13 @@ func (d *DockerVM)runContainer(dockerClient *client.Client) error{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
config := &container.Config{
|
||||||
|
Image : d.TagName,
|
||||||
|
Entrypoint: [] string {"/dockerstartup/vnc_startup.sh","/start"},
|
||||||
|
Volumes: map[string]struct{}{"/opt/data:/data":{}},
|
||||||
|
ExposedPorts: ExposedPort,
|
||||||
|
}
|
||||||
hostConfig := &container.HostConfig{
|
hostConfig := &container.HostConfig{
|
||||||
PortBindings: PortForwarding,
|
PortBindings: PortForwarding,
|
||||||
}
|
}
|
||||||
@@ -196,7 +207,6 @@ func print(rd io.Reader) error {
|
|||||||
scanner := bufio.NewScanner(rd)
|
scanner := bufio.NewScanner(rd)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
lastLine = scanner.Text()
|
lastLine = scanner.Text()
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errLine := &ErrorLine{}
|
errLine := &ErrorLine{}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDocker(t *testing.T) {
|
func TestDocker(t *testing.T) {
|
||||||
resp,err := BuildRunContainer()
|
resp,err := BuildRunContainer(2)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user