[RAILS] http: // localhost: How to change the port number

Connect the hello rails screen with your favorite port number

スクリーンショット 2021-01-12 15.40.42.png

procedure

Try connecting with port number 3000

docker-compose.yml


version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    tty: true
    stdin_open: true
    command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
    depends_on:
      - db

  db:
    image: mysql:8.0.16
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_HOST: 127.0.0.1
      MYSQL_DATABASE: app_development
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: root
    security_opt:
      - seccomp:unconfined
    ports:
      - "3306:3306"

Dockerfile


FROM ruby:2.6.5-stretch
ENV LANG C.UTF-8

ENV APP_ROOT /app
WORKDIR $APP_ROOT

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl apt-transport-https wget && \
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
    curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    vim \
    mysql-client \
    yarn \
    nodejs && \
    gem install bundler && \
    rm -rf /var/lib/apt/lists/*


COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install

COPY . $APP_ROOT

EXPOSE 3000

to start docker-compose up --build Enter the container docker-compose exec app bash Gemfile update bundle install Create a new project (choose mysql instead of sqlite) rails new . -d mysql Drop the container docker-compose down Set docker-compose db container password in database.yml docker-compose up

=> ** rails 3000 port boots **

Connect with port number 3001

docker-compose.yml


version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3001:3001"
    tty: true
    stdin_open: true
    command: bash -c "bundle exec rails s -p 3001 -b '0.0.0.0'"
    depends_on:
      - db

  db:
    image: mysql:8.0.16
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_HOST: 127.0.0.1
      MYSQL_DATABASE: app_development
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: root
    security_opt:
      - seccomp:unconfined
    ports:
      - "3306:3306"

Dockerfile


FROM ruby:2.6.5-stretch
ENV LANG C.UTF-8

ENV APP_ROOT /app
WORKDIR $APP_ROOT

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl apt-transport-https wget && \
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
    curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    vim \
    mysql-client \
    yarn \
    nodejs && \
    gem install bundler && \
    rm -rf /var/lib/apt/lists/*


COPY Gemfile $APP_ROOT
COPY Gemfile.lock $APP_ROOT
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN bundle install

COPY . $APP_ROOT

EXPOSE 3001

procedure

docker-compose.yml

--Specify ports 3001: 3001 in the rails startup container app. --Similarly, specify to listen on the released 3001 port with command.

Dockerfile

--Specified to open port 3001 in EXPOSE

http://localhost:3001 Rails starts with.

Recommended Posts

http: // localhost: How to change the port number
How to determine the number of parallels
How to change the timezone on Ubuntu
Ransack sort_link How to change the color!
Change SSH port number
How to change the maximum and maximum number of POST data in Spark
How to change the action with multiple submit buttons
[Ruby on Rails] How to change the column name
[Rails] How to change the column name of the table
Change the port with SpringBoot
How to number (number) with html.erb
How to dynamically change the column name acquired by MyBatis
Git How to easily return to the state before the change (before commit)
How to change the setting value of Springboot Hikari CP
How to change the contents of the jar file without decompressing
How to change the file name with Xcode (Refactor Rename)
How to use the link_to method
How to use the include? method
How to use the form_with method
How to find the average angle
How to use the wrapper class
How to change kube-proxy to ipvs mode.
How to add the delete function
How to change from HTML to Haml
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Rails] How to introduce kaminari with Slim and change the design
[Rails] How to change the page title of the browser for each page
[chown] How to change the owner of a file or directory
[Rails 5] How to display the password change screen when using devise
How to change app name in rails
[Java] How to use the File class
How to delete the wrong migration file
[Java] How to use the hasNext function
How to put out the error bundling
[Java] How to use the HashMap class
How to delete the migration file NO FILE
[Rails] How to use the map method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
[Swift] How to implement the countdown function
[Processing × Java] How to use the class
How to find the total number of pages when paging in Java
How to sort the List of SelectItem
How to install the legacy version [Java]
How to get the date in java
How to change the value of a variable at a breakpoint in intelliJ
[Processing × Java] How to use the function
[Rails] How to create a table, add a column, and change the column type
[Java] How to use the Calendar class
Summarized how to climb the programming stairs
[swift5] How to change the color of TabBar or the color of item of TabBar with code
[Swift] How to get the number of elements in an array (super basic)
[Rails] How to decide the destination by "rails routes"
How to find the cause of the Ruby error
How to use the camera module OV7725 (ESP32-WROVER-B)
How to check the logs in the Docker container
[Java] How to use Thread.sleep to pause the program
Customize how to divide the contents of Recyclerview
How to change Finder's default text editor to Atom