LoginSignup
2

More than 3 years have passed since last update.

Dockerfileについて

Posted at

Dockerfile

dockerfileはdockerの新しいイメージを作成する際に使用するもので
この設定ファイルにはrailsアプリケーション実行に必要なファイルやパッケージを
イメージに含めるための定義が書かれている。

Dockerfile.
1 FROM ruby:2.4.5
2 RUN apt-get update -qq && apt-get install -y build-essential nodejs
3 RUN mkdir /app
4 WORKDIR /app
5 COPY Gemfile /app/Gemfile
6 COPY Gemfile.lock /app/Gemfile.lock
7 RUN bundle install
8 COPY . /app

1 :から前の部分をリポジトリとよぶ。:から後の部分をタグという。
 この場合rubyリポジトリの2.4.5タグを示している。

2 ruby 2.4.5のイメージからコンテナを起動してコンテナ内で実行するコマンドを定義している
ubuntuのパッケージ管理システムであるapt-getでbuild-essential nodejsをインストールしてる
Railsの動作に必要

3 ルートディレクトリにappディレクトリを作成

4 作業用ディレクトリをappディレクトリに移動

5,6 PC上にあるGemfileとGemfilelockをappディレクトリにコピー

7 gemのインストールコマンドを実行

8 dockerファイルの置いてあるフォルダの内容を全ての内容をappディレクトリにコピー

dockerfile→build→dockerimageが作成される

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
2