Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container Development Practices #3

Open
ErezBinyamin opened this issue Dec 8, 2024 · 1 comment
Open

Container Development Practices #3

ErezBinyamin opened this issue Dec 8, 2024 · 1 comment

Comments

@ErezBinyamin
Copy link

Some suggestions to Dockerfiles.md based on some of my own personal development methods.

  • Use Makefiles to build / test / run
    • Track changes in dependent files/artifacts so as to rebuild images when necessary
    • Manage the frequently complex build, run, and management targets centrally
    • Version track Makefiles alongside container code and configuration files (Dockerfiles)
    • Use version-tracking ignored .keep files at build targets

Notional template makefile for a Docker project

IMAGE_NAME=iqtapp
DEPS=Dockerfile iqtapp.py iqtapp.config

KEEPFILE?=.imagebuild_$(IMAGE_NAME)
DOCKER_USERNAME?=erezbinyamin
PUSHTAG?=latest

build:$(KEEPFILE)
$(KEEPFILE): $(DEPS)
	docker build --tag $(IMAGE_NAME) .
	touch $(KEEPFILE)

rebuild:
	docker build --no-cache --tag $(IMAGE_NAME) .
	touch $(KEEPFILE)

bash: build
	docker run -it --network host --privileged $(IMAGE_NAME) bash

clean:
	docker images | grep -q "^$(IMAGE_NAME)" && docker image rm $(IMAGE_NAME) || true
	rm -f $(KEEPFILE)

push:
	docker tag $(IMAGE_NAME) $(DOCKER_USERNAME)/$(IMAGE_NAME):$(PUSHTAG)
	docker push $(DOCKER_USERNAME)/$(IMAGE_NAME)

help:
	@echo "Supported build targets:"
	@echo "  $(IMAGE_NAME): builds image"
	@echo "  build: .."
	@echo "  rebuild: .."
	@echo "  bash: launches shell inside container"
	@echo "  clean: removes docker image from local repository"
@ErezBinyamin
Copy link
Author

Using make alongside docker is a workflow that's been appreciated by several teams I've worked with professionally and one I am refining personally in my projects. For example: Neverland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant