user12073145
user12073145

Reputation:

Docker using Rails setup with errors

So I am creating a minimal rails app with postgresql database. I want to ensure the rails app works and make sure the docker and your working rails app are as similar as possible.

Here's my Dockerfile content:

FROM ruby:latest
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /rails_docker
WORKDIR /rails_docker
COPY Gemfile /rails_docker/Gemfile
COPY Gemfile.lock /rails_docker/Gemfile.lock
RUN bundle install
COPY . /rails_docker

And here's my docker-compose.yml file content:

version: '3'
services: 
  db:
    image: postgres
    restart: always
    environment: 
        POSTGRES_USER: 'samnorton'
        POSTGRES_PASSWORD: 'grace0512'
    volumes: 
        - postgres-data:/var/lib/postgresql/data
    ports: 
        - '9999:5432'
  web: 
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
        - .:/rails_docker
    ports:
        - "3000:3000"
    depends_on:
        - db
volumes:
  postgres-data:
    driver: local

I have also set up a minimal Gemfile and Gemfile lock. When I run sudo docker-compose up I run in the ff error:

data-K54C:~/Desktop/rails_docker$ sudo docker-compose up
[sudo] password for sam: 
railsdocker_db_1 is up-to-date
Starting railsdocker_web_1 ... 
Starting railsdocker_web_1 ... done
Attaching to railsdocker_db_1, railsdocker_web_1
db_1   | 2019-12-12 14:20:38.333 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-12 14:20:38.342 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-12 14:20:38.342 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-12 14:20:38.411 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-12 14:20:38.547 UTC [25] LOG:  database system was shut down at 2019-12-12 14:20:06 UTC
db_1   | 2019-12-12 14:20:38.609 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-12 14:24:47.800 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-12 14:24:47.841 UTC [1] LOG:  background worker "logical replication launcher" (PID 31) exited with exit code 1
db_1   | 2019-12-12 14:24:47.844 UTC [26] LOG:  shutting down
db_1   | 2019-12-12 14:24:48.094 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-12 15:54:38.528 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-12 15:54:38.543 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-12 15:54:38.543 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-12 15:54:38.627 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-12 15:54:38.806 UTC [23] LOG:  database system was shut down at 2019-12-12 14:24:48 UTC
db_1   | 2019-12-12 15:54:39.053 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-12 16:40:42.473 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-12 16:40:42.590 UTC [1] LOG:  background worker "logical replication launcher" (PID 29) exited with exit code 1
db_1   | 2019-12-12 16:40:42.590 UTC [24] LOG:  shutting down
db_1   | 2019-12-12 16:40:43.398 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-13 00:02:44.643 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-13 00:02:44.665 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-13 00:02:44.665 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-13 00:02:44.751 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-13 00:02:44.947 UTC [23] LOG:  database system was shut down at 2019-12-12 16:40:43 UTC
db_1   | 2019-12-13 00:02:45.179 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-13 00:32:00.742 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-13 00:32:01.089 UTC [1] LOG:  background worker "logical replication launcher" (PID 29) exited with exit code 1
db_1   | 2019-12-13 00:32:01.089 UTC [24] LOG:  shutting down
db_1   | 2019-12-13 00:32:02.353 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-13 01:01:34.874 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-13 01:01:34.896 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-13 01:01:34.896 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-13 01:01:35.035 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-13 01:01:35.479 UTC [23] LOG:  database system was shut down at 2019-12-13 00:32:01 UTC
db_1   | 2019-12-13 01:01:35.873 UTC [1] LOG:  database system is ready to accept connections
web_1  | Usage:
web_1  |   rails new APP_PATH [options]
web_1  | 
web_1  | Options:
web_1  |       [--skip-namespace], [--no-skip-namespace]            # Skip namespace (affects only isolated applications)
web_1  |   -r, [--ruby=PATH]                                        # Path to the Ruby binary of your choice
web_1  |                                                            # Default: /usr/local/bin/ruby
web_1  |   -m, [--template=TEMPLATE]                                # Path to some application template (can be a filesystem path or URL)
web_1  |   -d, [--database=DATABASE]                                # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
web_1  |                                                            # Default: sqlite3
web_1  |       [--skip-yarn], [--no-skip-yarn]                      # Don't use Yarn for managing JavaScript dependencies
web_1  |       [--skip-gemfile], [--no-skip-gemfile]                # Don't create a Gemfile
web_1  |   -G, [--skip-git], [--no-skip-git]                        # Skip .gitignore file
web_1  |       [--skip-keeps], [--no-skip-keeps]                    # Skip source control .keep files
web_1  |   -M, [--skip-action-mailer], [--no-skip-action-mailer]    # Skip Action Mailer files
web_1  |   -O, [--skip-active-record], [--no-skip-active-record]    # Skip Active Record files
web_1  |       [--skip-active-storage], [--no-skip-active-storage]  # Skip Active Storage files
web_1  |   -P, [--skip-puma], [--no-skip-puma]                      # Skip Puma related files
web_1  |   -C, [--skip-action-cable], [--no-skip-action-cable]      # Skip Action Cable files
web_1  |   -S, [--skip-sprockets], [--no-skip-sprockets]            # Skip Sprockets files
web_1  |       [--skip-spring], [--no-skip-spring]                  # Don't install Spring application preloader
web_1  |       [--skip-listen], [--no-skip-listen]                  # Don't generate configuration that depends on the listen gem
web_1  |       [--skip-coffee], [--no-skip-coffee]                  # Don't use CoffeeScript
web_1  |   -J, [--skip-javascript], [--no-skip-javascript]          # Skip JavaScript files
web_1  |       [--skip-turbolinks], [--no-skip-turbolinks]          # Skip turbolinks gem
web_1  |   -T, [--skip-test], [--no-skip-test]                      # Skip test files
web_1  |       [--skip-system-test], [--no-skip-system-test]        # Skip system test files
web_1  |       [--skip-bootsnap], [--no-skip-bootsnap]              # Skip bootsnap gem
web_1  |       [--dev], [--no-dev]                                  # Setup the application with Gemfile pointing to your Rails checkout
web_1  |       [--edge], [--no-edge]                                # Setup the application with Gemfile pointing to Rails repository
web_1  |       [--rc=RC]                                            # Path to file containing extra configuration options for rails command
web_1  |       [--no-rc], [--no-no-rc]                              # Skip loading of extra configuration options from .railsrc file
web_1  |       [--api], [--no-api]                                  # Preconfigure smaller stack for API only apps
web_1  |   -B, [--skip-bundle], [--no-skip-bundle]                  # Don't run bundle install
web_1  |       [--webpack=WEBPACK]                                  # Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular/elm/stimulus)
web_1  | 
web_1  | Runtime options:
web_1  |   -f, [--force]                    # Overwrite files that already exist
web_1  |   -p, [--pretend], [--no-pretend]  # Run but do not make any changes
web_1  |   -q, [--quiet], [--no-quiet]      # Suppress status output
web_1  |   -s, [--skip], [--no-skip]        # Skip files that already exist
web_1  | 
web_1  | Rails options:
web_1  |   -h, [--help], [--no-help]        # Show this help message and quit
web_1  |   -v, [--version], [--no-version]  # Show Rails version number and quit
web_1  | 
web_1  | Description:
web_1  |     The 'rails new' command creates a new Rails application with a default
web_1  |     directory structure and configuration at the path you specify.
web_1  | 
web_1  |     You can specify extra command-line arguments to be used every time
web_1  |     'rails new' runs in the .railsrc configuration file in your home directory.
web_1  | 
web_1  |     Note that the arguments specified in the .railsrc file don't affect the
web_1  |     defaults values shown above in this help message.
web_1  | 
web_1  | Example:
web_1  |     rails new ~/Code/Ruby/weblog
web_1  | 
web_1  |     This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
railsdocker_web_1 exited with code 0
in the the curent case you are not using the right rails directory i think

I am not sure if I am doing it right, I wonder if its the WORKDIR I have setup or something is running on port 3000. Any idea what is wrong with my setup?

UPDATE:

After running sudo docker-compose build and sudo docker-compose up I got these errors:

data-K54C:~/Desktop/rails_docker$ sudo docker-compose up
railsdocker_db_1 is up-to-date
Recreating railsdocker_web_1 ... 
Recreating railsdocker_web_1 ... error

ERROR: for railsdocker_web_1  no such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae: No such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae

ERROR: for web  no such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae: No such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae
ERROR: Encountered errors while bringing up the project.
sam@sam-K54C:~/Desktop/rails_docker$ clear

Upvotes: 0

Views: 524

Answers (1)

ZedTuX
ZedTuX

Reputation: 3027

Try to replace the command as the following:

command: bundle exec bin/rails s -p 3000 -b '0.0.0.0'

That should work.

Upvotes: 1

Related Questions