1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 10:17:26 +08:00

Merge pull request #41 from franela/devenv

Develop on a container
This commit is contained in:
Jonathan Leibiusky 2016-11-21 20:53:22 -03:00 committed by GitHub
commit dde46f897e
3 changed files with 48 additions and 0 deletions

26
Makefile Normal file
View File

@ -0,0 +1,26 @@
# Prepares the virtual box instance
prepare:
# Creates the virtual box
-docker-machine create -d virtualbox --virtualbox-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v1.13.0-rc1/boot2docker.iso pwd && true
# Makes sure the docker daemon has the DinD image pulled
-docker-machine ssh pwd "docker pull franela/pwd-1.12.3-experimental-dind"
# Daemon should be swarm
-docker-machine ssh pwd "docker swarm init --advertise-addr $$(docker-machine ip pwd)"
# Stops to daemon to do further configurations on the box
-docker-machine stop pwd
# Adds the host GOPATH as a shared folder in the box
-VBoxManage sharedfolder add pwd --name gopathsrc --hostpath ${GOPATH}src --automount
# Do port forwaring so we can reach the app using localhost:3000
-VBoxManage modifyvm pwd --natpf1 "localhost,tcp,,3000,,3000"
# Starts the virtual box instance
start:
# Starts the machine
-docker-machine start pwd
# Make sure the folder where we'll mount the shared folder exists
docker-machine ssh pwd "sudo mkdir -p /go/src"
# Mount the host's GOPATH shared folder
docker-machine ssh pwd "sudo mount -t vboxsf gopathsrc /go/src"
.PHONY: prepare start run

View File

@ -21,6 +21,11 @@ just run `docker swarm init`.
It's also necessary to manually load the IPVS kernel module because as swarms are created in `dind`,
the daemon won't load it automatically. Run the following command for that purpose: `sudo lsmod xt_ipvs`
If you are developing, there is a `Makefile` file with 2 targets that can set the whole environment for you (using docker-machine and virtual box).
Just run once `make create`, which will create the docker-machine environment.
Additionally, every time you want to start you environment run `make start`.
And to start the application on a container on the docker machine host, run: `eval $(docker-machine env pwd) && docker-compose up`
## Installation

17
docker-compose.yml Normal file
View File

@ -0,0 +1,17 @@
version: '2'
services:
web:
# pwd daemon container always needs to be named this way
container_name: pwd
# use the latest golang image
image: golang
# go to the right place and starts the app
command: /bin/sh -c 'cd /go/src/github.com/franela/play-with-docker; go run api.go'
ports:
# app exposes port 3000
- "3000:3000"
volumes:
# since this app creates networks and launches containers, we need to talk to docker daemon
- /var/run/docker.sock:/var/run/docker.sock
# mount the box mounted shared folder to the container
- /go/src:/go/src