LoginSignup
0
0

More than 5 years have passed since last update.

Docker 始めてみました。docker-compose 編

Last updated at Posted at 2018-12-30

overview

dockerは知っており、現場でも使っておりましたが、実際よくわかっておりませんでした。
vagrantの方が私にはわかりやすく、便利だったのでそちらを使っておりましたが、
最近になってdockerの便利さに心を打たれ使うことにしました。

環境

rails 5.2.2
ruby 2.5.0
OS cent os
web server: nginx
db: mysql5.7

上記の環境を構築します。

docker-compose


version: '2.1'

services:
  shichimi:
    container_name: shichimi
    stdin_open: true
    build: .
    environment:
      DB_HOST_NAME: db
    links:
      - db
    volumes:
      - .:/usr/share/nginx/html
      - ./default.conf:/etc/nginx/conf.d/default.conf 
      - bundle:/bundle
    ports:
      - 3000:3000
    tty: true
  db:
    container_name: shichimi_db
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: jobs_development
      MYSQL_USER: tomy
      MYAPP_DATABASE_PASSWORD: jamjam
    volumes:
      - ./.data/mysql:/var/lib/mysql
      - ./my.cnf.local:/etc/mysql/my.cnf
    ports:
      - 3307:3306
volumes:
  bundle:
    driver: local


FROM centos:centos6.9

MAINTAINER keisuke

ENV PATH $PATH:/usr/bin

RUN rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
RUN rpm -Uvh https://rpm.nodesource.com//pub_8.x/el/6/x86_64/nodejs-8.9.4-1nodesource.x86_64.rpm
RUN yum -y update
RUN yum -y install nginx gcc gcc-c++ git openssl-devel readline-devel zlib-devel mysql-devel wget
RUN git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
RUN git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
RUN wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.3.0/gcc-7.3.0.tar.gz
RUN tar zxvf gcc-7.3.0.tar.gz
WORKDIR gcc-7.3.0
RUN pwd
RUN ./contrib/download_prerequisites
RUN mkdir build
WORKDIR build
RUN ../configure --enable-languages=c,c++ --prefix=/usr/local --disable-bootstrap --disable-multilib
RUN make
RUN make install
RUN echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
RUN echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
WORKDIR /usr/share/nginx/html
RUN source ~/.bash_profile && rbenv install 2.5.0 && rbenv rehash && rbenv global 2.5.0 && ruby -v && gem install bundler
RUN cp /usr/local/lib64/libstdc++.so.6 /usr/lib64/
CMD ["/bin/bash"]

こんな感じになります、webserver は nginx なので、confファイルもマウントして使えるようにしておきます。

git hub sample code

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0