Skip to content

Docker compose cheatsheet

Adonis Lee Villamor edited this page Apr 9, 2020 · 1 revision

Docker compose is created thru using the 'docker-compose.yml' file. create one in any folder where you will run the commpand. A sample code is as follows

version: '3.0'

services:
  my-api:
    build: . # Build image from this directory (where the "Dockerfile" exists). it can specify paths as well
    ports: # specify used ports
      - "3000:3000"
    environment:
      - REDIS_HOST=redis-sessions # use the container name that we link to
      - REDIS_PORT=6379
      - USER_SESSION_MAX_TTL=1800
      - USER_SESSION_IDLE_TTL=120
    links:
      - redis-sessions # link this to our redis services
  redis-sessions:
    image: redis:5.0.8 # runs a specific image of redis
    ports: # expose the port so we can use some tools to look into the redis state from host
      - "6379:6379"

Build:

docker-compose build

Run

docker-compose up