Skip to content

Instantly share code, notes, and snippets.

@lordelph lordelph/Makefile
Last active Oct 19, 2016

Embed
What would you like to do?
# Example Makefile for docker builds
# See http://blog.dixo.net/2015/07/building-docker-containers-with-make-on-coreos/
#-----------------------------------------------------------------------------
# configuration - see also 'make help' for list of targets
#-----------------------------------------------------------------------------
# name of container
CONTAINER_NAME = myregistry.example.com:5000/mycontainer:latest
# list of dependancies in the build context - this example just finds all files
# in the 'files' subfolder
DEPS = $(shell find myfiles -type f -print)
# name of instance and other options you want to pass to docker run for testing
INSTANCE_NAME = mycontainer
RUN_OPTS =
#-----------------------------------------------------------------------------
# default target
#-----------------------------------------------------------------------------
all : ## Build the container - this is the default action
all: build
#-----------------------------------------------------------------------------
# build container
#-----------------------------------------------------------------------------
.built: . $(DEPS)
docker build -t $(CONTAINER_NAME) .
@docker inspect -f '{{.Id}}' $(CONTAINER_NAME) > .built
build : ## build the container
build: .built
clean : ## delete the image from docker
clean: stop
@$(RM) .built
-docker rmi $(CONTAINER_NAME)
re : ## clean and rebuild
re: clean all
#-----------------------------------------------------------------------------
# repository control
#-----------------------------------------------------------------------------
push : ## Push container to remote repository
push: build
docker push $(CONTAINER_NAME)
pull : ## Pull container from remote repository - might speed up rebuilds
pull:
docker pull $(CONTAINER_NAME)
#-----------------------------------------------------------------------------
# test container
#-----------------------------------------------------------------------------
run : ## Run the container as a daemon locally for testing
run: build stop
docker run -d --name=$(INSTANCE_NAME) $(RUN_OPTS) $(CONTAINER_NAME)
stop : ## Stop local test started by run
stop:
-docker stop $(INSTANCE_NAME)
-docker rm $(INSTANCE_NAME)
#-----------------------------------------------------------------------------
# supporting targets
#-----------------------------------------------------------------------------
help : ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
.PHONY : all build clean re push pull run stop help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.