-1

I have an ancient (like 2012) Ruby on Rails server that uses MySql2 database. The server, of course, is not made by me so I now have to find out how even launch it. And I want to use Docker for that.

I found this guide to setup Docker container for Rails and PostgreSQL database. So, what do I have to change here to run it with MySql2?

Here is my RoR server's database setup:

  adapter: mysql2
  encoding: utf8
  database: g_development
  pool: 5
  username: notactualusername
  password: notactualpassword

This is a line from Dockerfile in the tutorial that installs and updates all the stuff

RUN apt-get update -qq && apt-get install -y nodejs postgresql-client

I need to change postgresql to mysql2, right?

This is from tutorial docker-compose

  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password

So, is MySql2 image just called mysql2? Is the password variable called MYSQL2_PASSWORD or something else?

This is also from tutorial (initialization): docker compose run --no-deps web rails new . --force --database=postgresql

I guess changing here postgresql to mysql2? Do I actually need to run rails new . since I already have a server built?

  • The standard MySQL Docker Hub image is [`mysql`](https://hub.docker.com/_/mysql) ([`mariadb`](https://hub.docker.com/_/mariadb) is also an option) and the Docker Hub page describes its configuration options. – David Maze Aug 27 '22 at 12:22

1 Answers1

-1

If you want to use mysql, you need change database.yml

Don't forget run xampp

I use Ubuntu Linux

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV['USERNAME']%>
  password: <%= ENV['PAASSWORD']%>
  socket: /opt/lampp/var/mysql/mysql.sock           // run xampp 
  host: <%= ENV["DB_HOST"]%>
LihnNguyen
  • 632
  • 4
  • 10
  • I think you misunderstood me. My database.yml is a part of the Rails server and is already set up to use MySql2. And that's exactly why I'm asking how to set up Dockerfile and Docker-compose files for that type of database. – Alexander Vishnevskii Aug 27 '22 at 08:21
  • A `socket:` option won't work in Docker. – David Maze Aug 27 '22 at 12:22