Difficulty: Beginner
Estimated Time: 10 minutes

In this scenario you will learn how to run your Golang development environment inside a Docker container. We'll also discuss how to build a Docker image suitable for Golang applications.

This was created based on http://blog.benhall.me.uk

As demonstrated in this scenario, Makefiles make it really easy to manage the creation of Docker images. By having a single file you can organise the required commands for creating, debugging and releasing in a single and consistent approach.

NAME = ocelotuproar/docker-warden
  INSTANCE = docker-warden
  
  .PHONY: default build copy debug run release dev push
  
  default: build
  
  build:
      docker build -t $(NAME) .
  
  copy:
      docker create --name $(INSTANCE) $(NAME)
      docker cp $(INSTANCE):/go/bin/app $(shell pwd)/build
      docker rm $(INSTANCE)
  
  debug:
      docker run --rm -it --name $(INSTANCE) $(NAME) /bin/bash
  
  run:
      docker run --rm --name $(INSTANCE) $(NAME)
  
  dev:
      docker run -it --rm -w /go/src/github.com/$(NAME) -v $(shell pwd)/vendor/github.com/:/go/src/github.com/ -v $(shell pwd):/go/src/github.com/$(NAME) golang
  

Running Golang development environment inside Docker

Step 1 of 5

Step 1 - Golang Dev as Container

docker run -it --rm \
--name=godev \
-w /go/src/ \
-v $(pwd):/go/src/ \
golang
app.go