Skip to content

Instantly share code, notes, and snippets.

@mokxter
Last active March 31, 2019 15:42
Show Gist options
  • Save mokxter/bc88cf5a1f4993614cb6e1ac38e207b5 to your computer and use it in GitHub Desktop.
Save mokxter/bc88cf5a1f4993614cb6e1ac38e207b5 to your computer and use it in GitHub Desktop.

Revisions

  1. mokxter revised this gist Mar 31, 2019. 1 changed file with 0 additions and 12 deletions.
    12 changes: 0 additions & 12 deletions rails-docker.md
    Original file line number Diff line number Diff line change
    @@ -78,18 +78,6 @@ services:
    - '.:/app'
    - 'tmp:/app/tmp'
    - 'node_modules:/app/node_modules'
    webpack:
    build: .
    command: bash -c "./bin/webpack-dev-server"
    depends_on:
    - web
    ports:
    - '3035:3035'
    volumes:
    - '.:/app'
    - 'tmp:/app/tmp'
    - 'node_modules:/app/node_modules'
    ```

    ## Build the image / container
  2. mokxter revised this gist Mar 31, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails-docker.md
    Original file line number Diff line number Diff line change
    @@ -59,7 +59,7 @@ RUN bundle install
    COPY package.json yarn.lock /app/
    ```

    ### Create docker-compose.yml
    ## Create docker-compose.yml

    ```
    version: '3'
  3. mokxter revised this gist Mar 31, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails-docker.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ gem install rails
    ## Create project using rails gem
    ```
    cd workspace
    rails new app_name --webpack --skip-bundle
    rails new app_name --webpack
    # Exit the container after command have finished.
    exit
    ```
  4. mokxter revised this gist Mar 31, 2019. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions rails-docker.md
    Original file line number Diff line number Diff line change
    @@ -90,4 +90,11 @@ services:
    - '.:/app'
    - 'tmp:/app/tmp'
    - 'node_modules:/app/node_modules'
    ```

    ## Build the image / container
    ```
    docker-compose build
    # or
    docker-compose up
    ```
  5. mokxter created this gist Mar 31, 2019.
    93 changes: 93 additions & 0 deletions rails-docker.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    # Creating a Rails project with Docker.

    ## Pull ruby gem
    ```
    docker pull ruby:latest
    ```

    ## Run bash using ruby image.
    ```
    docker run -it -v "$(pwd):/workspace" ruby bash
    ```

    ## Install rails
    ```
    gem install rails
    ```

    ## Create project using rails gem
    ```
    cd workspace
    rails new app_name --webpack --skip-bundle
    # Exit the container after command have finished.
    exit
    ```

    ## Create Dockerfile
    ```
    cd app_anme
    touch Dockerfile
    vim Dockerfile
    ```
    ### Dockerfile sample / template
    ```
    FROM ruby:2.6.0
    ENV BUNDLE_JOBS=4 \
    BUNDLE_RETRY=3
    RUN apt-get update -qq && \
    apt-get install -y build-essential git
    RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install -y nodejs
    RUN npx n 10.15.0
    RUN 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 && \
    apt-get update && apt-get install -y yarn
    RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    WORKDIR /app
    COPY Gemfile Gemfile.lock /app/
    RUN bundle install
    COPY package.json yarn.lock /app/
    ```

    ### Create docker-compose.yml

    ```
    version: '3'
    volumes:
    tmp:
    node_modules:
    services:
    web:
    build: .
    command: bash -c "rm -rf /app/tmp/pids/service.pid && ./bin/rails s -p 3000 -b '0.0.0.0'"
    ports:
    - '3000:3000'
    volumes:
    - '.:/app'
    - 'tmp:/app/tmp'
    - 'node_modules:/app/node_modules'
    webpack:
    build: .
    command: bash -c "./bin/webpack-dev-server"
    depends_on:
    - web
    ports:
    - '3035:3035'
    volumes:
    - '.:/app'
    - 'tmp:/app/tmp'
    - 'node_modules:/app/node_modules'
    ```