Railsの開発環境をDockerで作った時にハマったところ Rails, Nginx, Redis, MySQL

docker-composeを使って構築する時にハマったところ


ホストマシン(Macのローカル環境)とDockerコンテナとのやりとり


 - ports ( -pオプション)でやりとりできるのはホストマシンのPortをマッピングする

なので

Dockerコンテナ同士のPortをマッピングしているわけではない

例えば、MySQLのコンテナ(Port:3306)にホストマシンからアクセスできるからといって、Railsを動かしているコンテナからアクセスはできない。


ホストマシン : mysql -h127.0.0.1 -uroot => OK
Railsコンテナ : mysql -h 127.0.0.1 -uroot => NG

linksを使って指定すれば、名前解決できるのでそれを使ってアクセスする

links:
    - mysql

Railsコンテナ : mysql -h mysql -uroot => OK


RailsアプリのMySQLへの接続、Redisへの接続などはホスト名の指定方法を変更する必要がある!!

修正前
database.yml
  host: localhost

development.rb
  config.session_store :redis_store,
                       servers: 'redis://localhost:6379/0',

修正後
database.yml
  url: mysql2://root:@mysql:3306

development.rb
  config.session_store :redis_store,
                       servers: 'redis://redis:6379/0',

Railsアプリの共有方法

ディレクトリ構成を以下のようにしていた

任意のディレクトリ/RailsApp/
  Gemfile
  app
  bin
  config
  db
  docker-compose/
    nginx/
      Dockerfile
      app.conf
    app/
      Dockerfile
    docker-compose.yml
    
そうすると、appのDockerfileに書くRailsAppのパスが親のパスになるため、Permissionエラーとなる

COPY .. /app
 
なのでdocker-compose.ymlとRailsアプリのDockerファイルはルートディレクトリに置くようにした



Xcode8 Swift3への対応

Swift3へのConvertでエラーとなって手動で直した部分


UICollectionDataSource

-    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
+    override func numberOfSections(in collectionView: UICollectionView) -> Int {


-    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {


-    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
+    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {



UITableViewDataSource


-    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
+    override func numberOfSections(in tableView: UITableView) -> Int {


-    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


-    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
+    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {



-    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
+
+    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {



CGGeometory

-        frame = CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height)
+       frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height)


UIVIewController

-     override func shouldAutomaticallyForwardAppearanceMethods() -> Bool {
+    override var shouldAutomaticallyForwardAppearanceMethods: Bool {



Cocoapods

"Use Legacy Swift Language Version"のエラーが出た場合、該当のフレームワークのBuild Settingsで「Use Legacy Swift Language Version」の設定をNOにする



ReactNativeでAndroid対応する話

前提 ReactNativeでiOS版のアプリをリリースしていて、Android版をリリースする話 トラブルシューティング Build.VERSION_CODES.Q が存在しないエラー compileSdkVersionを29以上にすると解決 メモリー足りないエラー Execu...