Amazon Linux2 Ruby2.6 の Dockerfile 

# Amazon Linux2 Ruby2.6 の Dockerfile 

```
FROM amazonlinux:2

# 日本語設定
RUN yum install -y glibc-langpack-ja && yum clean all
ENV LANG ja_JP.utf8
ENV LC_ALL ja_JP.utf8

RUN unlink /etc/localtime \
    && ln -s /usr/share/zoneinfo/Japan /etc/localtime

# パッケージインストール
RUN yum update -y \
    && yum install -y amazon-linux-extras \
    && amazon-linux-extras install -y ruby2.6 \
    && amazon-linux-extras install -y epel \
    && yum install -y sudo shadow-utils procps which net-tools \
    && yum groupinstall -y "Development tools" \
    && yum install -y kernel-devel kernel-headers \
    && yum install -y vim wget curl git zip ImageMagick \
    && yum install -y ruby-devel rubygems-devel \
    && yum install -y mailx mariadb mariadb-devel sqlite-devel

# nodejs インストール
RUN curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo bash - \
    && yum -y install nodejs \
    && npm install -g n \
    && npm install --save-dev -g -f grunt \
    && npm install --save-dev -g -f grunt-cli \
    && npm install --save-dev -g -f webpack

## yarn インストール
RUN curl -sSL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo \
    && rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg \
    && yum install -y yarn

RUN mkdir /app
ENV APP_ROOT /app
WORKDIR $APP_ROOT

# bash_profile
RUN echo -e "alias ls='ls --color=auto --show-control-chars --time-style=long-iso --human-readable --classify'\nalias ll='ls -l'\nalias la='ls -A'\nalias grep='grep --color'\nalias less='less --raw-control-chars'\nalias whence='type -a'" >> ~/.bashrc \
    && echo -e "if [ -f ~/.bashrc ]; then\n  source ~/.bashrc\nfi" >> ~/.bash_profile \
    && source ~/.bash_profile

# SQLite3インストール
RUN cd \
    && wget https://www.sqlite.org/2021/sqlite-autoconf-3340100.tar.gz \
    && tar xzvf sqlite-autoconf-3340100.tar.gz \
    && cd sqlite-autoconf-3340100 \
    && ./configure --prefix=/opt/sqlite/sqlite3 \
    && make \
    && make install \
    && gem install sqlite3 -- --with-sqlite3-include=/opt/sqlite/sqlite3/include --with-sqlite3-lib=/opt/sqlite/sqlite3/lib \
    && echo 'export LD_LIBRARY_PATH="/opt/sqlite/sqlite3/lib"' >> ~/.bashrc \
    && source ~/.bash_profile

# direnv
RUN wget -O direnv https://github.com/direnv/direnv/releases/download/v2.27.0/direnv.linux-amd64 \
    && chmod +x direnv \
    && sudo mv direnv /usr/bin/ \
    && echo -e "direnv allow ." >> ~/.bashrc \
    && echo -e 'eval "$(direnv hook bash)"' >> ~/.bashrc \
    && source ~/.bash_profile

# bundle インストール
RUN gem install bundle

# postfix（mailhog用）
#   ipv6を有効にする
#   もしくは
#   /etc/hosts の「::1」から始まる行をコメントアウトし、
#   「/sbin/postfix start -D」を実行しないと動かない。。。
RUN yum install -y postfix \
    && postconf -e relayhost=mail:1025 \
    && /sbin/postfix start -D
```

## docker-compose.yml

```
version: "3.7"

services:
  db:
    container_name: db
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: '1111'
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: '1111'
      TZ: 'Asia/Tokyo'
    ports:
      - "3306:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./.docker/mysql/initdb.d:/docker-entrypoint-initdb.d

  app:
    container_name: app
    build: .
    environment:
      MYSQL_HOST: db
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: '1111'
    ports:
      # ruby-debug-ide 用
      - "1234:1234"
      - "26162:26162"
      # rails用
      - "3000:3000"
    depends_on:
      - db
    tty: true
    stdin_open: true
    privileged: true
    volumes:
      - .:/app

  mail:
    container_name: mail
    image: mailhog/mailhog
    ports:
      - "8025:8025"
      - "1025:1025"

volumes:
  db_data:
    driver: local
```

## ./.docker/mysql/initdb.d:/docker-entrypoint-initdb.d/00_grant.sql

```
GRANT ALL PRIVILEGES ON *.* TO dbuser;
```