Files
grecia/docker-compose.yml
Javi Martín 40d82037d1 Don't overwrite node_modules with Docker Compose
When creating the Dockerfile, we run `npm install`, which creates a
`node_modules` folder inside the working directory.

However, when using docker-compose, we overwrite the contents of that
working directory (/var/www/consul) with the contents of the host
machine's working directory. This means that, unless the `npm install`
command is run on the host machine to create a `node_modules` folder on
the host machine (which would pretty much defeat the point of using
Docker), the container won't have a `node_modules` folder and the
application won't run.

So we're defining a volume in docker-compose.yml to make sure we keep
the container's `node_modules` folder.
2024-09-18 15:01:59 +02:00

43 lines
1.1 KiB
YAML

version: "3"
services:
# service configuration for our database
database:
# use the preferred version of the official Postgres image
# see https://hub.docker.com/_/postgres/
image: postgres:9.6.21
environment:
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
# persist the database between containers by storing it in a volume
volumes:
- db_data:/var/lib/postgresql/data
# service configuration for our dockerized Rails app
app:
# use the Dockerfile next to this file
build: .
# rely on the RAILS_ENV value of the host machine
# environment:
#RAILS_ENV: $RAILS_ENV
# makes the app container aware of the DB container
depends_on:
- database
# expose the port we configured Unicorn to bind to
ports:
- "3000:3000"
# map our application source code, in full, to the application root of our container
volumes:
- .:/var/www/consul
- bundle:/usr/local/bundle
- node_modules:/var/www/consul/node_modules
environment:
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
volumes:
db_data: {}
bundle: {}
node_modules: {}