Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Last active April 12, 2024 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonbosa/28944de0bdf57c1bf0ac3601f6715e7f to your computer and use it in GitHub Desktop.
Save andersonbosa/28944de0bdf57c1bf0ac3601f6715e7f to your computer and use it in GitHub Desktop.
Generic Makefile to help you boost your productivity with Docker

Variables

DOCKER_IMAGE_NAME := my-docker-image DOCKER_CONTAINER_NAME := my-container DOCKER_BUILD_DIR := . DOCKERFILE := Dockerfile DOCKER_RUN_COMMAND := /bin/bash

Commands

build: docker build -t $(DOCKER_IMAGE_NAME) -f $(DOCKER_BUILD_DIR)/$(DOCKERFILE) $(DOCKER_BUILD_DIR)

run: docker run -it --rm --name $(DOCKER_CONTAINER_NAME) $(DOCKER_IMAGE_NAME) $(DOCKER_RUN_COMMAND)

shell: docker exec -it $(DOCKER_CONTAINER_NAME) $(DOCKER_RUN_COMMAND)

stop: docker stop $(DOCKER_CONTAINER_NAME)

restart: docker restart $(DOCKER_CONTAINER_NAME)

clean: docker rm $(DOCKER_CONTAINER_NAME) -f docker rmi $(DOCKER_IMAGE_NAME)

.PHONY: build run stop restart clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment