https://github.com/zcubbs/go-containers
This Go package provides a simple interface for running Docker containers directly from a host system.
https://github.com/zcubbs/go-containers
docker go
Last synced: about 1 month ago
JSON representation
This Go package provides a simple interface for running Docker containers directly from a host system.
- Host: GitHub
- URL: https://github.com/zcubbs/go-containers
- Owner: zcubbs
- License: mit
- Created: 2023-08-04T01:32:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-04T02:24:20.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T11:48:28.803Z (over 1 year ago)
- Topics: docker, go
- Language: Go
- Homepage: https://pkg.go.dev/github.com/zcubbs/go-containers
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-containers: Go Docker Containers package
[](https://github.com/zcubbs/go-containers/releases)

[](https://pkg.go.dev/github.com/zcubbs/go-containers)

[](https://goreportcard.com/report/github.com/zcubbs/go-containers)
[](https://codecov.io/gh/zcubbs/go-containers)
[](https://github.com/zcubbs/go-containers/graphs/contributors)
[](./LICENSE)
This Go package provides a simple interface for running Docker containers directly from a host system.
## Features
- **Pull Docker Image**: The `RunContainerOnHost` function pulls a Docker image from a Docker registry.
- **Create Docker Container**: The function creates a Docker container from the pulled image.
- **Run Docker Container**: It then runs the Docker container on the host.
- **Wait For Container To Complete**: The function waits for the Docker container to finish its execution.
- **Fetch Logs**: It fetches and prints the logs of the Docker container to `os.Stdout`.
## Dependencies
This package uses the following dependencies:
- `context`: Standard Go package for carrying deadlines, cancellations signals, and other request-scoped values across API boundaries.
- `github.com/docker/docker/api/types`: Docker API types.
- `github.com/docker/docker/api/types/container`: Docker container types.
- `github.com/docker/docker/client`: Docker client to interact with Docker API.
- `io`: Standard Go package for basic interfaces to I/O primitives.
- `os`: Standard Go package that provides a platform-independent interface to operating system functionality.
## Usage
```go
package main
import (
"github.com/zcubbs/gocontainers"
)
func main() {
image := "ubuntu:latest"
cmd := []string{"/bin/sh", "-c", "echo Hello, World"}
err := gocontainers.RunContainerOnHost(image, cmd)
if err != nil {
panic(err)
}
}
```
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.