├── LICENSE ├── README.md ├── database-golang-app ├── Dockerfile └── main.go ├── docker-compose.yml ├── simple-golang-app.yml └── simple-golang-app └── main.go /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Larry Price 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is source code for a blog post available at: 2 | 3 | [https://larry-price.com/blog/2015/02/26/a-quick-guide-to-using-docker-compose-previously-fig/](https://larry-price.com/blog/2015/02/26/a-quick-guide-to-using-docker-compose-previously-fig/) 4 | 5 | Happy composing! 6 | -------------------------------------------------------------------------------- /database-golang-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.4 2 | 3 | RUN go get gopkg.in/mgo.v2 4 | -------------------------------------------------------------------------------- /database-golang-app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gopkg.in/mgo.v2" 6 | "gopkg.in/mgo.v2/bson" 7 | "os" 8 | "time" 9 | ) 10 | 11 | type Ping struct { 12 | Id bson.ObjectId `bson:"_id"` 13 | Time time.Time `bson:"time"` 14 | } 15 | 16 | func main() { 17 | session, err := mgo.Dial(os.Getenv("DATABASE_PORT_27017_TCP_ADDR")) 18 | 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | db := session.DB(os.Getenv("DB_NAME")) 24 | defer session.Close() 25 | 26 | ping := Ping{ 27 | Id: bson.NewObjectId(), 28 | Time: time.Now(), 29 | } 30 | db.C("pings").Insert(ping) 31 | 32 | pings := []Ping{} 33 | db.C("pings").Find(nil).All(&pings) 34 | 35 | fmt.Println(pings) 36 | } 37 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | advanced: 2 | build: ./database-golang-app 3 | working_dir: /go/src/database-golang-app 4 | command: go run main.go 5 | volumes: 6 | - ./database-golang-app:/go/src/database-golang-app 7 | links: 8 | - database 9 | environment: 10 | - DB_NAME=advanced-golang-db 11 | database: 12 | image: mongo:3.0 13 | command: mongod --smallfiles --quiet --logpath=/dev/null -------------------------------------------------------------------------------- /simple-golang-app.yml: -------------------------------------------------------------------------------- 1 | simple: 2 | image: golang:1.4 3 | working_dir: /go/src/simple-golang-app 4 | command: go run main.go 5 | volumes: 6 | - ./simple-golang-app:/go/src/simple-golang-app -------------------------------------------------------------------------------- /simple-golang-app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello, World") 7 | } 8 | --------------------------------------------------------------------------------