To run mysql 5.6 on a Docker centos:centos6 image

Asked 2 months ago, Updated 2 months ago, 2 views

I would like to have my new Rails project run on DockerToolbox.
The Rails version is 4.0.0.

#...set up abbreviated Docker Toolbox...

$ git clone path /to /repository.git project
$ cd project
# Install gem
$ bundle -- path vendor/bundle
# Start config
$ config up-d
# Migration performed (DB already created)
$ rakedb:migrate

The above rake task will fail.
The error details are as follows:

Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE installed:...

As per Note, if the MySQL version is 5.7.3 or later, MySQL appears to be causing an error due to the activerecord implementation.

So I tried to change the MySQL version to 5.6 series, but I can't do it well.
The Dockerfile of fig.yml and mysql is as follows.

fig.yml

mysql:
  build:./docker/mysql
  environment:
    - MYSQL_ROOT_PASSWORD=password
  volumes_from:
    - data
  ports:
    - "3306:3306"
data:
  image:centos:centos6
  command: /bin/bash
  volumes:
    - /data
    - /var/lib/mysql

docker/mysql/Dockerfile

 FROM mysql:5.6

RUN cp-p/usr/share/zoneinfo/Asia/Tokyo/etc/localtime

ADD config /my.cnf /etc/my.cnf

This is what happens in this state.

$fig build
$ config up-d
$ figps
# =>Name Command State Ports
# =>----------------------------------------------------------------------------------------------------------------------
# =>app_data_1/bin/bash Exit 0
# =>app_mysql_1/entrypoint.sh mysqld Exit1
# 

Here is the result of fig logs.

 mysql_1 | mkdir:cannot create directory ''': No such file or directory

I understand that here is an error, but I don't know what to do from now on.

ruby-on-rails mysql docker

2022-09-30 14:20

1 Answers

Could you tell me the environment of the docker?
rakedb: I thought it might be possible to execute migration only in the container.

My execution environment uses boot2docker for docker-machine on OSX.In this environment, mysqld, which was guided by docker hub mysql, was launched as follows:

%docker run --name some-mysql-e MYSQL_ROOT_PASSWORD=my-secret-pw-d mysql:5.6

This mysqld shows the 3306/tcp port from the docker-machine virtual host (I am VirtualBox), and the 3306/tcp port is not visible on the terminal where this command was issued.

You may be able to run the rails application by placing it in a docker container.

%docker run-it --link some-mysql:mysql --rm your-rails-app-container'rakedb:create&rakedb:migrate&rails'

That's all.


2022-09-30 14:20

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.