Skip to content

Instantly share code, notes, and snippets.

@michaelbunch
Last active December 7, 2021 10:04
Show Gist options
  • Save michaelbunch/826a1cc40e59de098311895d2afd36c8 to your computer and use it in GitHub Desktop.
Save michaelbunch/826a1cc40e59de098311895d2afd36c8 to your computer and use it in GitHub Desktop.
Local Docker Services

Local Docker Services

Run Docker containers like they are native services with Docker so they can be locally accessible to the host computer with their default settings.

Requirements

  • Docker
  • Docker-compose

Services

  • Nginx Reverse Proxy
  • MySQL
  • Redis
  • Minio
  • MongoDB

How to run

Download the docker-compose.yaml file included in this Gist to somewhere on your hard drive. From that folder run:

docker-compose up -d

This will load all the services listed. To only run select services include the service at the and of the previous command:

docker-compose up -d proxy mysql

Persistent Storage

Each of the included services has container volume to persist data between system restarts. To remove a volume you will need to stop the service it belongs to then remove the volume. To remove the mysql data volume you would run:

docker-compose stop mysql
docker volume rm mysql-data

To recreate the data volume start the container again.

docker-compose start mysql

Tear Down

You can remove all containers, volumes, and networks created by this file by running:

docker-compose down -v --rmi all

Within the context of this docker-compose.yaml the command will:

  • Stop and remove all services
  • Remove the specified network
  • Remove all container volumes
  • Delete downloaded images for the defined services

If you receive an error that any of the containers, volumes, or networks are currently in use then you will need to stop all containers linking to them and run the command again.

Gotchas

Port Conflicts

Since the ports used are default to their respective services you could have conflicts with other local instances. You may need to stop or remove those service from the host computer before running service included here.

version: '3.7'
x-defaults: &defaults
restart: unless-stopped
networks:
- learninghouse
services:
# Nginx Reverse Proxy
# https://github.com/jwilder/nginx-proxy
proxy:
<<: *defaults
container_name: proxy
image: jwilder/nginx-proxy:alpine
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
ports:
- 80:80
- 443:443
# MySQL Relational Database Server
# https://www.mysql.com/
mysql:
<<: *defaults
image: mysql:5.7
container_name: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- mysql-data:/var/lib/mysql
# Redis: In-memory Data Structure Store
# https://redis.io/
redis:
<<: *defaults
image: redis:4.0-alpine
container_name: redis
ports:
- 6379:6379
volumes:
- redis-data:/data
# Minio: Private Cloud Storage
# https://www.minio.io/
minio:
<<: *defaults
image: minio/minio
container_name: minio
command: ["server", "/data"]
environment:
MINIO_ACCESS_KEY: V88PXXYC1QGOYFS9KQMQ
MINIO_SECRET_KEY: FK0J4GyIZwbKbnEjyi2rnzkfBaiOxkYFAsD0wgRq
VIRTUAL_PORT: 9000
VIRTUAL_HOST: minio.local.learninghouse.com
volumes:
- minio-data:/data
- minio-config:/root/.minio
# MongoDB: NoSQL Document Store
# https://www.mongodb.com/
mongodb:
<<: *defaults
image: mongo:3.6
container_name: mongodb
ports:
- 27017:27017
volumes:
- mongo-data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: secret
volumes:
minio-data:
name: minio-data
minio-config:
name: minio-config
mysql-data:
name: mysql-data
redis-data:
name: redis-data
mongo-data:
name: mongo-data
networks:
learninghouse:
name: dev-proxy_learninghouse
driver: bridge
ipam:
driver: default
config:
- subnet: 172.30.0.0/16
@michaelbunch
Copy link
Author

Add RabbitMQ and MongoDB

@michaelbunch
Copy link
Author

MongoDB added. The network changed to learninghouse to be consistent with project documentation and settings.

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