Skip to content

Instantly share code, notes, and snippets.

@rednafi
Created September 5, 2020 09:52
Show Gist options
  • Save rednafi/7b95f4f6774366a74b4d0df6b276197d to your computer and use it in GitHub Desktop.
Save rednafi/7b95f4f6774366a74b4d0df6b276197d to your computer and use it in GitHub Desktop.
A rudimentary Dockerfile & docker-compose.yml for Python projects
version: '3.7'
services:
master:
image: rednafi/locust-template:v1
container_name: locust-master
build:
context: ./
ports:
- 8089:8089
volumes:
- ./:/code/
command: -f /code/locustfiles/locustfile.py --master
worker:
image: rednafi/locust-template:v1
volumes:
- ./:/code/
command: -f /code/locustfiles/locustfile.py --worker --master-host master
#!/bin/bash
docker-compose down
# Remove dangling images (-q=quiet, -f=without prompt)
docker rmi $(docker images -q -f dangling=true)
# Remove all stopped containers
docker rm -v $(docker ps -a -q -f status=exited)
# Remove dangling volumes
docker volume rm $(docker volume ls -qf dangling=true)
# Spin up the new container
# The if-else and the getopts is to take in the worker argument
if getopts "n:" arg; then
docker-compose -f docker-compose.yml up \
-d \
--build \
--scale worker=$OPTARG
else
docker-compose -f docker-compose.yml up \
-d \
--build \
--scale worker=1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment