Skip to content

Instantly share code, notes, and snippets.

@julianxhokaxhiu
Last active June 16, 2022 15:09
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 julianxhokaxhiu/bd6d3a61cb6c9f68ce8c6a1708701882 to your computer and use it in GitHub Desktop.
Save julianxhokaxhiu/bd6d3a61cb6c9f68ce8c6a1708701882 to your computer and use it in GitHub Desktop.
Docker compose example project with proxy support

How to use

Requirements

  1. Docker v20.10.17+
  2. Docker Compose v2.6.0

Proxy setup

If you're behind a Proxy, make sure you add your proxy settings in your own ~/.docker/config.json file using the example described here: https://docs.docker.com/network/proxy/#configure-the-docker-client

Build and Run

You can now use these simple commands to build and run your docker-compose project (with or without proxy):

# Builds containers with `build` sections defined
$ make

# Starts the stack
$ make start

# Get logs from the stack
$ make logs

# Stops the stack
$ make stop

# Restarts the stack
$ make restart

# Cleanup everything ( useful for fresh starts )
$ make clean
version: "3.8"
services:
example:
# It is important to define this one so the container is seen as "one" between build and start/restart/stop
image: example:latest
# Build a local container
build:
context: .
dockerfile: Dockerfile
# Use this network to ensure custom domains are resolved using your own DNS and not Google DNS
network: host
# Run the container within a custom network
networks:
- example
networks:
example:
FROM alpine:latest
###############################################################################
# ENVIRONMENT CONFIGURATION
###############################################################################
MAKEFLAGS += --no-print-directory
SHELL=/bin/bash
# Use default as default goal when running 'make'
.PHONY: default
.DEFAULT_GOAL := default
###############################################################################
# GOALS ( safe defaults )
###############################################################################
# 'docker buildx bake' approach is required since it is able to inherit
# proxy configuration unlike 'docker-compose build/up'
default:
@docker buildx bake -f docker-compose.yml
start:
@docker-compose up --detach
restart:
@docker-compose restart
stop:
@docker-compose stop
logs:
@docker-compose logs -f
clean:
@docker-compose down --rmi all --remove-orphans --volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment