compose/containers/api.go

89 lines
2.6 KiB
Go
Raw Normal View History

2020-06-18 16:13:24 +02:00
/*
Copyright 2020 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package containers
import (
"context"
2020-05-03 13:35:25 +02:00
"io"
)
2020-05-03 13:35:25 +02:00
// Container represents a created container
type Container struct {
ID string
Status string
Image string
Command string
CPUTime uint64
MemoryUsage uint64
MemoryLimit uint64
PidsCurrent uint64
PidsLimit uint64
Labels []string
2020-05-14 12:17:06 +02:00
Ports []Port
}
2020-05-03 13:35:25 +02:00
// Port represents a published port of a container
2020-05-01 15:28:44 +02:00
type Port struct {
2020-05-14 12:17:06 +02:00
// HostPort is the port number on the host
HostPort uint32
// ContainerPort is the port number inside the container
ContainerPort uint32
// Protocol is the protocol of the port mapping
2020-05-14 12:17:06 +02:00
Protocol string
// HostIP is the host ip to use
HostIP string
2020-05-01 15:28:44 +02:00
}
2020-05-03 13:35:25 +02:00
// ContainerConfig contains the configuration data about a container
2020-05-01 15:28:44 +02:00
type ContainerConfig struct {
2020-05-03 13:35:25 +02:00
// ID uniquely identifies the container
ID string
// Image specifies the iamge reference used for a container
2020-05-01 15:28:44 +02:00
Image string
2020-05-03 13:35:25 +02:00
// Ports provide a list of published ports
2020-05-01 15:28:44 +02:00
Ports []Port
2020-05-18 10:33:01 +02:00
// Labels set labels to the container
Labels map[string]string
// Volumes to be mounted
Volumes []string
2020-05-01 15:28:44 +02:00
}
// LogsRequest contains configuration about a log request
2020-05-04 16:38:02 +02:00
type LogsRequest struct {
Follow bool
Tail string
Writer io.Writer
}
// Service interacts with the underlying container backend
type Service interface {
2020-05-03 13:35:25 +02:00
// List returns all the containers
2020-05-16 12:13:51 +02:00
List(ctx context.Context, all bool) ([]Container, error)
// Stop stops the running container
Stop(ctx context.Context, containerID string, timeout *uint32) error
2020-05-03 13:35:25 +02:00
// Run creates and starts a container
Run(ctx context.Context, config ContainerConfig) error
// Exec executes a command inside a running container
Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
2020-05-03 13:41:45 +02:00
// Logs returns all the logs of a container
2020-05-04 16:38:02 +02:00
Logs(ctx context.Context, containerName string, request LogsRequest) error
// Delete removes containers
Delete(ctx context.Context, id string, force bool) error
// Inspect get a specific container
Inspect(ctx context.Context, id string) (Container, error)
}