Home>

Prerequisite and realization

Ruby on Rails6 I would like to build a Ruby on Rails environment with Docker using a book of practice guide.
When the following command is executed, an error appears and seems not to be connected to the database. Please tell us the solution.

Occurrence Issues /Error Messages

BASH-4.4 $ BIN /RAILS DB: CREATE
COULD NOT TRANSLATE HOST NAME "DB" To Address: NAME DOES NOT RESOLVE
COULDN'T CREATE 'BAUKIS2_DEVELOPMENT' DATABASE. PLEASE CHECK YOUR CONFIGURATION.
Rails ABORTED!
PG :: ConnectionBad: COULD NOT TRANSLATE HOST NAME "DB" To Address: NAME DOES NOT RESOLVE
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb: 58: In `initialize '
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb: 58: Inn` new '
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb: 58:in `Connect '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/postgreSQL_Adapter.rb:46: `PostgreSQL_CONNECTION '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/Connection_pool.rb: 889: In` new_connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/Connection_pool.rb: 933: In` checkout_new_connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/connection_pool.rb: 912: In` TRY_TO_CHECKOUT_NEW_CONNECTION '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/Connection_pool.rb: 873: In` Acquire_Connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb: 595: In` checkout '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/connection_pool.rb: 439: In` connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_adapters/abstract/connection_pool.rb:1121: In` retrieve_connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_handling.rb: 238: In` retrieve_connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/Connection_handling.rb:206: In` connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/postgreSQL_DATABASE_TASKS.RB:12: 21 Connection '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/postgreSQL_DATABASE_TASKS.RB:21: 21: `CREATE '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:126: In` CREATE
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:185: In `block in create_current '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb: 479: In `block (2 Levels) in Each_current_configuration '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb: 476: In` Each '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb: 476: In` block in Each_Current_Configuration '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb: 475: In` Each '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb: 475: In` Each_Current_Configuration '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:184: In` CREATE_CURRENT '
/usr/local/bundle/gems/activeRecord-6.0.2.2/lib/active_record/railtiltilties/databases.rake:39:29: Inn `Block (2 Levels) In <
Main >
'
/usr/local/bundle/gems/railtilties-6.0.2.2/lib/rails/commands/rake/rake_command.rb: 23:in `Block in Perform '
/usr/local/bundle/gems/railtilties-6.0.2.2/lib/rails/commands/rake/rake_command.rb:20: In `perform '
/usr/local/bundle/gems/railtilties-6.0.2.2/lib/rails/command.rb: 48: In` INVOKE '
/usr/local/bundle/gems/railtilties-6.0.2.2/lib/rails/commands.rb:18: In` <
Main >
'
/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb: 23:in `Require '
/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb: 23:in `block in Require_with_bootsnap_lfi '
/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb: 92: In `register '/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi '/usr /local /bundle /gems /bootsnap-1.4.6 /lib /BOOTSNAP /LOAD_PATH_CACHE /CORE_EXT /KERNEL_REQUIRE.RB: 31: IN `REQUIRE '
/usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb: 325: In `block in Require '
/usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb: 291: In` Load_Dependency '
/usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb: 325: In `Require '
/Apps /Baukis2 /Bin /Rails: 9: IN `<
TOP (REQUIRED) >
'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb: 28: In` Load '
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb: 28: In` Call '
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7: In `Call '
/usr/local/bundle/gems/Spring-2.1.0/lib/spring/client.rb:30:in `Run '
/usr/local/bundle/gems/spring-2.1.0/bin/spring: 49: In` <
TOP (REQUIRED) >
'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:1: `Load '
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11: In` <
TOP (REQUIRED) >
'
/APPS /BAUKIS2 /BIN /SPRING: 15: IN `<
TOP (REQUIRED) >
'
bin /rails: 3: in `load '
Bin /Rails: 3: IN `<
Main >
'
Tasks: TOP= >
 DB: CREATE
(See Full Trace by Running Task with --trace)

Corresponding source code

DATABASE.YML

# PostgreSQL. Versions 9.3 and up aRe Supported.
#
# Install the pg driver:
# GEM Install PG
# On macos with homebrew:
# GEM INSTALL PG --with-pg-config= /usr /local /bin /pg_config
# On macos with MacPorts:
# Gem install pg ---with-pg-config= /opt /local /lib /postgreesql84 /bin /pg_config
# On Windows:
# GEM Install PG
# Choose The Win32 build.
# Install PostgreSQL and Put ITS /Bin Directory On Your Path.
#
# Configure using gemfile
# GEM 'PG'
#
DEFAULT: &
DEFAULT
  Adapter: PostgreSQL
  EncoDing: Unicode
  # For Details on Connection Pooling, See Rails Configuration Guide
  # Https://guides.rubyonrails.org/configuring.html#database-pooling
  POOL: <
%= Env.fetch ("Rails_max_threads") {5}% >
  Host: DB
  Username: Postgres
  Password: ""
Development:
  ≪
≪
* DEFAULT
  Database: baukis2_development
  # The Specified Database Role Being Used to Connect to Postgres.
  # To Create Additional Roles in Postgres See `$ CREATEUSER --Help`.
  # While Left Blank, Postgres Will Use the Default Role.
  # The Same Name As The Operating System User That Initialized The Database.
  #USERNAME: BAUKIS2
  # The Password Associated With The Postgres Role (Username).
  #Password:
  # Connect on a TCP Socket. Omitted by Default Since The Client Uses A
  # Domain Socket That Doesn't Need Configuration. Windows Does Not Have
  # Domain Sockets, So Uncomment These Lines.
  #Host: localhost
  # The TCP Port The Server Listens on. Defaults to 5432.
  # IF Your Server Runs on a Different Port Number, Change Accordingly.
  # Port: 5432
  # Schema search path. The Server Defaults To $ User, Public
  #Schema_search_path: MyApp, SharedApp, Public
  # Minimum Log Levels, In Increasing Order:
  # Debug5, debug4, debug3, debug2, debug1,
  # Log, Notice, Warning, Error, Fatal, and Panic
  # DEFAULTS To Warning.
  #Min_messages: Notice
# 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: BAUKIS2_TEST
# As with config /Credentials.yml, You Never Want to Store Sensitive Information,
# Like Your Database Password, In Your Source Code. IF Your Source Code IS
# Ever Seen by Anyone, They Now Have Access to Your Database.
#
# Instead, Provide The Password AS A UNIX Environment Variable When You Boot
# The app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-Database
# For a Full Rundown on How To Provide These Environment Variables in A
# Production Deployment.
## On Heroku and Other Platform Providers, You May Have A Full Connection URL # Available as An Environment Variable. For example:
#
# DATABASE_URL= "Postgres: //myUser: mypass @ localhost /Somedatabase"
#
# You can use this Database Configuration with:
#
# Production:
# Url: <
%= Env ['database_url']% >
#
Production:
  ≪
≪
* DEFAULT
  Database: baukis2_production
  Username: baukis2
  Password: <
%= Env ['baukis2_database_password']% >

docker-compose.yml

Version: '3'
Services:
  DB:
    Image: Postgres: 11.2-alpine
    Volumes:
      -./tmp/db:/var/lib/postgreesql/data
  WEB:
    Build:.
    Command: /bin /sh
    Environment:
      WebPacker_Dev_Server_Host: "0.0.0.0"
      Rails_serve_static_files: "1"
      Editor: "Vim"
    Volumes:
      -./apps:/apps
    Ports:
      -"3000: 3000"
      -"3035: 3035"
    DEPENDS_ON:
      -DB
    TTY: TRUE

DOCKERFILE

From OIAX /RAILS6-DEPS: LATEST
Arg uid= 1000
Arg GID= 1000
RUN MKDIR /VAR /MAIL
Run groupadd -g $ gid devel
Run useradd -u $ uid -g devel -m devel
RUN ECHO "DEVEL ALL= (ALL) NOPASSWD: ALL" >
≫
 /etc /sudoers
WorkDir /TMP
COPY INIT /GEMFILE /TMP /GEMFILE
Copy init /gemfile.lock /tmp/gemfile.lock
Run Bundle Install
Copy ./apps /apps
Run apk add --no-cache openssl
User Devel
RUN OpenSSL RAND-Hex 64 >
 /home/devel/.secret_key_base
RUN ECHO $ ​​'EXPORT SECRET_KEY_BASE= $ (CAT /HOME/DEVEL/.Secret_Key_Base)' \
  ≫
≫
 /home/devel/.bashrc
Workdir /Apps

Try to be tried

  1. Docker-Compose Run Web Rails DB: CREATE: COMPOSE RUN WEB RAILSRunned, but there was no change.
  2. config /database.yml User was rooted and executed, but there was no change.
  3. Host of
  4. config /database.yml was LocalHost, but it did not change.

When I checked the process of PostgreSQL
It was not present

ps -ef | grep ps -ef | Grep Post
DEVEL 1407 1333 0 09:46 PTS /1 00:00:00 Grep Post

A plurality of cases were confirmed if a directory for PostgreSQL exists.
However, how to check and start the status of the service and do not know.

FIND /-Type F | XARGS Grep Postgres