Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何基于 docker 开始一个新的Rails项目 #14

Open
alvin2ye opened this issue Jun 2, 2021 · 0 comments
Open

如何基于 docker 开始一个新的Rails项目 #14

alvin2ye opened this issue Jun 2, 2021 · 0 comments

Comments

@alvin2ye
Copy link
Owner

alvin2ye commented Jun 2, 2021

cat <<EOF >> Dockerfile

FROM ruby:3-alpine3.13
EXPOSE 3000

RUN apk add --update \
  build-base \
  mariadb-dev \
  nodejs yarn \
  tzdata \
  && rm -rf /var/cache/apk/*

RUN mkdir -p /app
WORKDIR /app
VOLUME /app

ADD Dockerfile /Dockerfile
CMD ["sh", "-c", "env >> /etc/environment ; tail -f /dev/null"]

EOF

# docker-compose.yml

cat <<EOF >> docker-compose.yml

version: "3"

services:
  mysql:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=root
    volumes:
      - "mysql_data:/var/lib/mysql"
      - ".:/app"
  main:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - ".:/app"
      - "ruby_bundle:/usr/local/bundle"
      - "~/.ssh/id_rsa:/root/.ssh/id_rsa"
    depends_on:
      - mysql
volumes:
  mysql_data:

EOF

docker-compose up -d
docker-compose exec main sh -c "gem install rails"
docker-compose exec main sh -c "rails new . -d mysql"
vim database.yml
docker-compose exec main sh -c "rake db:create"
docker-compose exec main sh -c "rails s -b 0.0.0.0"


# 可能用到
# docker-compose exec main sh -c "bundle"
# docker-compose exec main sh -c "rails webpacker:install"


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant