Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active January 11, 2021 21:09
Show Gist options
  • Save percybolmer/316fcd397fbdad96cbb91624d9f15c13 to your computer and use it in GitHub Desktop.
Save percybolmer/316fcd397fbdad96cbb91624d9f15c13 to your computer and use it in GitHub Desktop.
Example docker-compose.yaml used in Medium post
# This compose is for demonstration how to serve our custom image and a prebuilt image
version: "3.0"
#Services defines what containers to run
services:
#server is the name for our custom image, this can be anything and is used by other services to refer to this.
server:
#the image to run the container from
image: "learndocker:0.2"
# set environments
environment:
- PORT=8080
# bind ports to our host
ports:
- 8082:8080
# connect this container to the database container by settting them on the same virutal network
networks:
- amazing_network
# Name our service database, this can be anything. The name is used to refer to this service from others, such as reaching their IP
database:
# Use the postgres image, this will be donwloaded for you automatically from Dockerhub
image: "postgres"
ports:
# Expose and bind our ports
- 8083:5432
environment:
- POSTGRES_USER=percybolmer
- POSTGRES_PASSWORD=topsecret
- POSTGRES_DB=mydatabase
#env_file:
# Read in a file called database.env
# - database.env
#volumes:
# - ./api/db-data:/var/lib/postgresql/data/ # persist data even if container shuts down
networks:
- amazing_network
networks:
# Create the network amazing_network
amazing_network:
driver: bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment