diff --git a/docker/docker.go b/docker/docker.go index ea76b5e..f95858c 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "io" "io/ioutil" "log" @@ -306,22 +305,22 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i return "", err } - portmaps := nat.PortMap{} - - portbindingsHTTP := make([]nat.PortBinding, 1) - portbindingsHTTP[0] = nat.PortBinding{ - HostIP: "0.0.0.0", - HostPort: strconv.Itoa(HTTPPort), + portBindings := nat.PortMap{ + "8000/tcp": []nat.PortBinding{ + { + HostIP: "0.0.0.0", + HostPort: strconv.Itoa(HTTPPort), + }, + }, } - portmaps["8000"] = portbindingsHTTP if SSHPort != 0 { - portbindingsSSH := make([]nat.PortBinding, 1) - portbindingsSSH[0] = nat.PortBinding{ - HostIP: "0.0.0.0", - HostPort: strconv.Itoa(SSHPort), + portBindings["22/tcp"] = []nat.PortBinding{ + { + HostIP: "0.0.0.0", + HostPort: strconv.Itoa(SSHPort), + }, } - portmaps["22"] = portbindingsSSH } createdContainer, err := cli.ContainerCreate( @@ -331,6 +330,10 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i Env: []string{}, Image: image, Cmd: cmd, + ExposedPorts: nat.PortSet{ + nat.Port("22/tcp"): struct{}{}, + nat.Port("8000/tcp"): struct{}{}, + }, }, &container.HostConfig{ Resources: container.Resources{ @@ -339,7 +342,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i Memory: int64(memory*110/100) * 1024 * 1024, // Allow 10 % more memory so we have space for MemoryReservation MemoryReservation: int64(memory) * 1024 * 1024, // This should provide softer way how to limit the memory of our containers }, - PortBindings: portmaps, + PortBindings: portBindings, AutoRemove: false, RestartPolicy: container.RestartPolicy{ Name: "on-failure", @@ -427,7 +430,6 @@ func (d *Driver) Exec(name string, cmd []string, stdin string, env []string, att stdouterr := []byte{} if attachStdout { stdouterr, err = ioutil.ReadAll(respAttach.Reader) - fmt.Println(string(stdouterr)) } return &stdouterr, err diff --git a/docker/types.go b/docker/types.go index 4a57615..15ecb43 100644 --- a/docker/types.go +++ b/docker/types.go @@ -14,8 +14,8 @@ const passwordFile = "/srv/.rosti" // Process contains info about background application usually running in supervisor type Process struct { - Name string - State string + Name string `json:"name"` + State string `json:"state"` } // Container extends App struct from App