This example illustrates how to link Docker containers with following images. Docker version is 1.2.0.
- golang1.3.3-onbuild
- postgres:9.3.5
If you are on Mac OSX, follows the next Boot2Docker section.
As described on here, you should configure your network before you start a boot2docker VM.
$ boot2docker init
$ ./for-boot2docker.sh
$ boot2docker upYou can pull official postgres and run it simply.
$ docker run --name some-postgres -d postgres:9.3.5You'll be able to see postgres with docker ps.
At first, you need to build the app to an image.
$ docker build --tag="test:1.0" .Since you started a postgres container, you can link that with --link flag.
$ docker run -p 49153:8080 --name some-app --link some-postgres:postgres -d test:1.0
The docker ps will show something similar to below.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f87470a6c176 test:1.0 "go-wrapper run" 22 minutes ago Up 22 minutes 0.0.0.0:49153->8080/tcp some-app
32cc507dce51 postgres:9.3.5 "/docker-entrypoint. 26 minutes ago Up 26 minutes 5432/tcp some-app/postgres,some-postgres
You can see the app with curl.
$ curl http://localhost:49153/
Or if you are using boot2docker with Mac OSX, You need to know to IP address that boot2docker VM is on.
$ boot2docker ip # it'll show ip address
$ # assume the IP address is 192.168.59.103
$ curl http://192.168.59.103:49153/