Name: rancher-docker-api-proxy
Owner: Rancher
Description: Library to access Docker socket through Rancher API WebSocket Proxy
Created: 2015-10-28 05:20:49.0
Updated: 2018-02-22 21:53:51.0
Pushed: 2018-01-25 06:23:18.0
Homepage: null
Size: 15
Language: Go
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is very simple library to access the Docker socket through the Rancher API. This allows one to communicate with Docker without exposing the Docker socket through TLS or any public port.
age main
rt (
"os"
"github.com/Sirupsen/logrus"
rancher "github.com/rancher/go-rancher/v2"
main() {
// Simple example of using this library. Run this as follows
//
// go run main/main.go myhost unix:///tmp/myhost.sock
//
// Then run `docker -H unix:///tmp/myhost.sock ps`
if err := run(); err != nil {
logrus.Fatal(err)
}
run() error {
logrus.SetLevel(logrus.DebugLevel)
client, err := rancher.NewRancherClient(&rancher.ClientOpts{
Url: os.Getenv("CATTLE_URL"),
AccessKey: os.Getenv("CATTLE_ACCESS_KEY"),
SecretKey: os.Getenv("CATTLE_SECRET_KEY"),
})
if err != nil {
return err
}
proxy := dockerapiproxy.NewProxy(client, .Args(1), os.Args(2))
return proxy.ListenAndServe()
Construct a docker API client routing through Rancher.
NewAPIClient(...) (client.APIClient, error) {
httpClient, err := newHTTPClient(host, tlsOptions.TLSOptions)
if err != nil {
return nil, err
}
return client.NewClient(host, verStr, httpClient, customHeaders)
newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
client, err := rancher.NewRancherClient(&rancher.ClientOpts{
Url: "http://localhost:8080",
})
if err != nil {
return nil, err
}
// second arguement can be host id, name, or hostname
dialer, err := dockerapiproxy.NewDialer(client, "1h123")
if err != nil {
return nil, err
}
return &http.Client{
Transport: &http.Transport{
Dial: dialer,
},
}, nil
Copyright (c) 2014-2015 Rancher Labs, 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.