Tiny Go Docker Client middleware for Echo.
go get github.com/joseluisq/echo-dockerclient
Or via Dep
dep ensure -add github.com/joseluisq/echo-dockerclient
package main
import (
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/joseluisq/echo-dockerclient"
)
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// 1. First, add the Docker Client middleware to Echo server
// Option 1:
// Docker Client instance with the given server endpoint
e.Use(dockerc.DockerClient("unix:///var/run/docker.sock"))
// Option 2:
// Or if you're using `docker-machine` or another application that exports
// the Docker environment variables like DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH
e.Use(dockerc.DockerClientFromEnv())
// 2. Finally, get the Docker Client instance in controller
e.GET("/images", func (c echo.Context) error {
client := c.Get("docker-client").(*docker.Client)
images, err := client.ListImages(docker.ListImagesOptions{All: false})
return c.JSON(200, images)
})
}
For more details, check out the echo-dockerclient package and the Docker Engine API documentation.
Pull requests and issues are very appreciated.
MIT license
© 2018 José Luis Quintana