Skip to content

syb-devs/dockerlink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Dockerlink

Build Status

Dockerlink is a small package to get data (IP Address, port, protocol) of a linked Docker container.

More about Docker linking

Usage example

Given two containers setup as follows:

$ docker run -d --name db mongo
$ docker run -d -P --name goweb --link db:db myrepo/goapp

Where the first one is running a MongoDB server and the second one is our Golang web app, we could use the package to get the IP address and port to connect to the MongoDB database from within our Go app in the second container:

package main

import (
	"github.com/syb-devs/dockerlink"
	"gopkg.in/mgo.v2"
)

func main() {
	link, err := dockerlink.GetLink("db", 27017, "tcp")
	if err != nil {
		panic(err)
	}

	session, err := mgo.Dial(fmt.Sprintf("%s:%d", link.Address, link.Port))
	if err != nil {
		panic(err)
	}
	...
}

About

Small utility for getting Docker linked containers data (IP Address, port, protocol...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages