Skip to content

Instantly share code, notes, and snippets.

@TerminalFi
Created February 22, 2022 00:06
Show Gist options
  • Save TerminalFi/7b2629d9019a876bcf778e7ea57c5907 to your computer and use it in GitHub Desktop.
Save TerminalFi/7b2629d9019a876bcf778e7ea57c5907 to your computer and use it in GitHub Desktop.
Docker Compose Example / Database + App
version: "3.9"
# Definitions of the Services related to the Compose File.
# Each service is it's own container, Docker Compose handles
# starting the services
services:
# Database (MongoDB)
database:
# Image is related to a image locally or on a remote Docker Registry
image: mongo
container_name: mongodb
# Environment allows you to set environment variables within the container
environment:
- PUID=1000
- PGID=1000
# Volumes sets up a local to remote mapping. Allowing you to persist data between restarts
volumes:
- ./database:/data/db
# Ports defines which ports your container should expose.
# In this case, we expose 27017 and map it to port 27017 inside the container
ports:
- 27017:27017
restart: unless-stopped
# User Service
shield:
# Build tells docker that we are using a local Dockerfile instead of pulling a remote image.
build:
# The name of our local Dockerfile
dockerfile: Dockerfile
# The name of the Image once built See Dockerfile for why it is important
target: dev
# Where the docker file resides.
context: .
container_name: shield
# Depends On tells docker to start the database before running this service
depends_on:
- "database"
environment:
- PUID=1000
- PGID=1000
- FURIOUS_CONFIG=config/staging.yaml
- FURIOUS_MONGO_DB=A80FD952-B226-4FFA-B57F-0FD8F53FF9EF
volumes:
- ./database:/data/db
ports:
- 6710:6710
restart: unless-stopped
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
# Start from golang:1.17-alpine base image and name the image `dev`
FROM golang:1.17-alpine as dev
# Add a work directory within the Container (not locally)
WORKDIR /app
# Copy local files from the current working directory into ./ in the container
COPY go.mod go.sum ./
# This Command is RUN inside of the Container.
RUN go mod download
# Copy app files
# This is copying local files in the CWD into the CWD of the Container
COPY . .
# Install Reflex for development
# Another command run inside of the container
RUN go install github.com/cespare/reflex@latest
# Expose port
# Exposes the following port from the container to the local environment
EXPOSE 6710
# Start app
# CMD is the entry point. The final command which should be long running.
CMD go run main.go serve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment