Run docker container in testing for golang.
You should run docker on local.
Check this command.
$ docker version
If this command occurred error, you should install docker in your PC beforehand.
Install Docker
ex. travis
.travis.yml
language: go
go:
- tip
sudo: false
services:
- docker # here
script:
go test -v ./...
$ go get -u github.com/takecy/gockertest
for public registry. [see redis example](./example/redis/redis.go)
args := gockertest.Arguments{
Ports: map[int]int{6379: 6379},
}
cli := gockertest.Run("redis:3.2-alpine", args)
defer cli.Cleanup()
for private registy with basic authentication.
see redis example
args := gockertest.Arguments{
Ports: map[int]int{6379: 6379},
RequireLogin: true, // require basic authentication
Login: gockertest.Login{
User: "yourname", // change to your username
Password: "pass", // change to your password
Registry: "registry.yours.io", // change to your registy domain
},
}
cli := gockertest.Run("registry.yours.io/redis:3.2-alpine", args)
defer cli.Cleanup()
- --net
- -p
- --name
- --rm
- -d
Because --link
is legacy.
Official Docs
You should use network features.
$ make test