# Docker # Dockerfile build image ```dockerfile FROM ruby:3.0.4 RUN bundle config --global frozen 0 RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ curl -fsSL https://deb.nodesource.com/setup_lts.x | bash && \ apt-get update && apt-get install -y python2.7 nodejs mariadb-client cron yarn --no-install-recommends && \ rm -rf /var/lib/apt/lists/* ENV APP_PATH /usr/src/app RUN mkdir -p $APP_PATH WORKDIR $APP_PATH COPY Gemfile* $APP_PATH/ # RUN gem update --system && bundle install RUN gem update bundler --no-document \ && gem clean bundler \ && bundle update --bundler \ && bundle install COPY . $APP_PATH/ EXPOSE 3000 ``` # initdb.sql ```sql CREATE DATABASE `instant_messaging_v2_development` CHARACTER SET utf8mb4; CREATE DATABASE `instant_messaging_v2_test` CHARACTER SET utf8mb4; ``` # docker-compose.yml ```compose version: '3' services: db: image: mariadb:10.6.9 restart: always ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: qwer4321 command: | --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password volumes: - mariadb-data-volume:/var/lib/mysql - ./docker/db:/docker-entrypoint-initdb.d app: build: context: . dockerfile: ./docker/app/Dockerfile command: | bash -c "yarn install --check-files && \ bundle install && \ rake db:migrate && \ rm -f tmp/pids/server.pid && \ rails s -b '0.0.0.0' -p 3000" stdin_open: true tty: true volumes: - .:/usr/src/app - ~/.ssh:/root/.ssh:ro - bundle-volume:/usr/local/bundle ports: - 3000:3000 env_file: .env environment: - REDIS_URL_CACHING=redis://redis:6379/0 - WEBPACKER_DEV_SERVER_HOST=webpack depends_on: - db - redis redis: image: redis command: ["redis-server", "--appendonly", "yes"] ports: - 6379:6379 volumes: - redis:/data sidekiq: image: xxx-app:latest volumes: - .:/usr/src/app - bundle-volume:/usr/local/bundle command: bundle exec sidekiq -C config/sidekiq.yml depends_on: - redis - app webpacker: image: xxx-app:latest volumes: - .:/usr/src/app - bundle-volume:/usr/local/bundle # env_file: .env environment: - NODE_ENV=development - RAILS_ENV=development - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 command: bash -c "yarn install --check-files && BRAND=h6 ./bin/webpack-dev-server" ports: - 3035:3035 depends_on: - app volumes: bundle-volume: mariadb-data-volume: redis: ``` # webpacker.yml ```yml development: dev_server: host: 0.0.0.0 port: 3035 public: 0.0.0.0:3035 ``` ```bash # build image docker-compose build docker-compose up # build & run ``` ```yaml abc: - a - b - c abc: >- a b c ``` ./bin/dev irb