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 **
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
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