我正在使用docker-compose运行带有mysql db docker镜像的rails应用程序。
docker-compose build 很好; docker-compose up 也可以,即使有一些警告(mysql图像版本问题)
...
db_1 | MySQL init process done. Ready for start up.
db_1 | [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
...
db_1 | [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1 | [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1 | [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1 | Version: '5.7.10' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
db_1 | Version: '5.7.10' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
web_1 | [2016-02-11 18:38:10] INFO WEBrick 1.3.1
web_1 | [2016-02-11 18:38:10] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux]
web_1 | [2016-02-11 18:38:10] INFO WEBrick::HTTPServer#start: pid=1 port=3000
当我在另一个终端上运行迁移命令 docker-compose运行web rake db:create | migrate 时,我得到了当前错误( docker-compose up ):
db_1 | [Note] Aborted connection 2 to db: 'unconnected' user: 'root' host: '172.17.0.4' (Got an error reading communication packets)
...
db_1 | [Note] Aborted connection 3 to db: 'unconnected' user: 'root' host: '172.17.0.4' (Got an error reading communication packets)
这是我的 Dockerfile :
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install -y build-essential
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
EXPOSE 3000
这是我的 docker-compose.yml :
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
links:
- db
这是我的 database.yml :
default: &default
adapter: mysql2
pool: 5
encoding: utf8
host: db
username: root
password: password
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
有关详细信息,请参阅entire scenario