Docker Community Forums

Share and learn in the Docker community.

Docker rails app using mariadb

Hello, I have Rails app in docker and also mariadb docker image.

But it fails during connection on

2021-11-05 8:27:49 3 [Warning] Aborted connection 3 to db: ‘development’ user: ‘root’ host: ‘172.18.0.4’ (Got an error reading communication packets)``

and rails app fails on

*** stack smashing detected ***: <unknown> terminated

My dockerfile is

FROM ruby:2.6.5

RUN apt-get update; apt-get install -y build-essential nodejs npm vim htop
RUN npm install --global yarn

RUN mkdir -p /app
WORKDIR /app

ENV BUNDLER_VERSION=2.1.4

COPY Gemfile Gemfile.lock /app/

RUN gem install bundler:2.1.4
RUN bundle install --jobs 20 --retry 5
RUN yarn install --silent --no-progress --no-audit --no-optional --check-files

#RUN bundle exec rake db:migrate

# Copy the main application.
COPY . ./

RUN rm -f /app/tmp/pids/server.pid

EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

Mariadb dockerfile is (note that is for my localhost development so no passwords required)

FROM mariadb


RUN apt-get update; apt-get install -y build-essential vim htop

ENV MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes
ENV MARIADB_DATABASE=development
ENV MARIADB_USER=root

COPY ./schema.sql /docker-entrypoint-initdb.d/a-schema.sql
COPY ./data.sql /docker-entrypoint-initdb.d/b-data.sql


And composer file

services:
  app:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    links:
      - mariadb
    environment:
      WEBPACKER_DEV_SERVER_HOST: webpack
      RAILS_ENV: development
      RACK_ENV: development
      DATABASE: development
      DB_USERNAME: root
      DB_HOST: mariadb
      LOCALISATION: cs
    depends_on:
      - webpack

  mariadb:
    build:
      context: .
      dockerfile: Dockerfile.mariadb
    restart: on-failure
    volumes:
      - ./mariadb:/var/lib/mysql

  webpack:
    build: .
    command: ./bin/webpack-dev-server
    #volumes:
    #  - .:/app
    ports:
      - '3035:3035'
    environment:
      NODE_ENV: development
      RAILS_ENV: development
      WEBPACKER_DEV_SERVER_HOST: 0.0.0.0

UPDATE: when I try to connect from app container to database using mysql_client it works, also app starts and checks for migrations but in next selects falls down.

UPDATE2: I fixed first error with *** stack smashing detected ***: <unknown> terminated by upgrading mini_racer gem from git repo, but connection to mysql is stil crashing :/.

Please any suggestions? It drives me mad