我正在尝试构建一个docker容器来将MySql数据库迁移到Postgresql。计划是使用docker-compose.yml中的每个服务器的广告图像,但我的初始图像构建失败
我的dockerfile:
FROM ruby:2.4.0
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
mysql-client \
libmysqlclient-dev \
libpq-dev \
RUN mkdir -p /app
WORKDIR /app
RUN gem install mysql2psql
但是我收到了一个错误:
Building native extensions. This could take a while...
ERROR: Error installing mysql2psql:
ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/mysql-2.8.1/ext/mysql_api
/usr/local/bin/ruby -r ./siteconf20180130-1553-1id0936.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/$(RUBY_BASE_NAME)
--with-mysql-config
--without-mysql-config
extconf.rb:67:in `<main>': uninitialized constant Config (NameError)
Did you mean? RbConfig
CONFIG
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/bundle/extensions/x86_64-linux/2.4.0/mysql-2.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /usr/local/bundle/gems/mysql-2.8.1 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.4.0/mysql-2.8.1/gem_make.out
我错过了什么?
答案 0 :(得分:0)
首先,您的Dockerfile中有错误:您不应将\
放在RUN
命令的末尾。
你安装这个宝石的问题与它太旧有关。这个gem需要gem mysql -v '2.8.1'
,它只与Ruby 2.1或更早版本兼容。
因此,要使其正常工作,您可以使用FROM ruby:2.1
或使用其他gem来更改您的ruby版本,例如:https://github.com/maxlapshin/mysql2postgres。
工作解决方案:
FROM ruby:2.1
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
mysql-client \
libmysqlclient-dev \
libpq-dev
RUN mkdir -p /app
WORKDIR /app
RUN gem install mysql2psql