Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

joseluisq/echo-dockerclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

echo-dockerclient Build Status

Tiny Go Docker Client middleware for Echo.

Install

go get github.com/joseluisq/echo-dockerclient

Or via Dep

dep ensure -add github.com/joseluisq/echo-dockerclient

Usage

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.

Contributions

Pull requests and issues are very appreciated.

License

MIT license

© 2018 José Luis Quintana