Rails app in docker returns database does not exists after successfully running rake db:create

  docker, postgresql, ruby-on-rails

I’m dockerizing the app I’ve been working on, but there’s something I’ve been scratching my head trying out to figure out the reason why.

After the database is successfully created with

docker-compose run web rake db:create

Created database 'db_dev'
Created database 'db_test'

When I try to run the migration command

docker-compose run web rake db:migrate

It returns

database "db_dev" does not exist

If the command is executed again, the migration will be performed.

What could be the reason?

Here is my docker-compose.yml config

version: "3.8"
services:
  db:
    image: postgres:12.7
    volumes:
      - data:/var/lib/postgresql/data
    environment:
      - POSTGRES_HOST_AUTH_METHOD=password
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=the_password
    ports:
      - "5432:5432"
    networks:
      - the_net
  web:
    tty: true
    stdin_open: true
    build: .
    image: the_app:latest
    command: bundle exec rails s -p 3001 -b '0.0.0.0'
    environment:
      - DB_HOST=db
      - DB_USER=postgres
      - DB_PASSWORD=the_password
    env_file:
      - .env
    volumes:
      - .:/myapp
    ports:
      - "3001:3001"
    depends_on:
      - db
    networks:
      - the_net
volumes:
  data:
networks:
  the_net:
    external: true
    name: the_net

Thanks in advance

Source: Docker Questions

LEAVE A COMMENT