Currently i'm using docker compose to connect my web app with the postgre database. My config looks like this:
# Dockerfile
FROM rails:onbuild
RUN rake db:create db:migrate db:seed
# config/database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
encoding: utf8
database: rezeptr_prod
pool: 5
username: postgres
password:
host: db
development:
<<: *default
database: rezeptr_dev
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: rezeptr_test
# docker-compose.yml
db:
image: postgres
web:
build: .
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
links:
- db:db
If i run docker-compose up
i get this error
could not translate host name "db" to address: Name or service not known
If i don't run rake db:create ...
in the Dockerfile and run it like this docker-compose run web rake db:create
it works fine and i don't get any errors. Can you help me?
Yes, links are not available during the build phase. There are a few ways to get your fixtures installed during build, but none of them are really straightforward:
Dockerfile
for the database, add all the project source, and ruby dependencies, and run the rake db:create
as part of the image buildrake db:create
as part of the entrypoint script of a database image (something I'm not a fan of, and don't really recommend)Okay cool! :+1: First, thank you for your long description! I will run it as a manual step, this should be enough for now. Later i could think about further steps!
@dazorni Could you please update the steps to solve. I got into this and try to discover. I know it's difficult to reproduce, but really appreciate if you can show :) .
Most helpful comment
Yes, links are not available during the build phase. There are a few ways to get your fixtures installed during build, but none of them are really straightforward:
Dockerfile
for the database, add all the project source, and ruby dependencies, and run therake db:create
as part of the image buildrake db:create
as part of the entrypoint script of a database image (something I'm not a fan of, and don't really recommend)