# 環境構築

### Docker環境の構築

環境構築にDockerを使用します。

それぞれのOSに合わせてインストールをしてください。

本書で使用しているDockerとdocker-composeとのバージョンを下記に記載します。

```
Docker version 20.10.2
docker-compose version 1.17.
```

### フォルダ構成の作成

Dockerとdocker-composeのインストールが完了したら以下のフォルダを作成してください。

```
ruby-practice/
　├ docker-compose.yml
　├ code/
　│　└ Dockerfile
　│　└ main.rb
　│　└ hello.rb
```

### Dockerfileの修正

Dockerfileに以下の内容を記述してください。

```
FROM ruby:3.1
WORKDIR /code
```

### docker-compose.ymlの修正

docker-compose.ymlに以下の内容を記述してください。

```yaml
version: '3'

services:
  code:
    container_name: code
    build: 
      context: ./code
    volumes:
      - ./code:/code
    tty: true
```

### デモ用rubyコードの作成

hello.rbの中に以下の内容を記載してください。

後でrubyが正常に動いているかどうかの確認に使うものです。

```ruby
puts "hello"
```

### Dockerの立ち上げと確認作業

dockerファイルとdocker-composeファイルへの記載が完了したらコンテナを立ち上げます。

以下のコマンド群をruby-practiceフォルダ直下で実行してください

```
docker-compose build 
docker-compose up -d
```

docker psコマンドで環境が正常に立ち上がっていることを確認します

```
docker ps
```

codeコンテナが立ち上がっている事を確認した後、以下のコマンドを実行してコンテナ内に入りましょう。

```
docker exec -ti code /bin/bash
```

コンテナの中に入れたらrubyのバージョンを確認して、rubyが使える環境であることを確認してください。

```
ruby -v
```

確認が完了したら、先程実装したrubyのコードを実行してみましょう

```
ruby hello.rb
```

helloと帰ってきたら環境構築成功です

```
hello
```

確認が終わったらexitコマンドでコンテナから抜けます

```
exit
```

docker-composeをdownさせておきます。

開発を始める時はup -d。終わる時はdownさせます。

```
docker-compose down
```

これにて環境構築はおしまいです。

作業をする場合はdocker-compose upしてコンテナに入ってrubyコードを実行します。

確認作業が終わればhello.rbは消しちゃってください。

次ページからRubyを使って三目並べのロジックを実装していきましょう！


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kashiwara.gitbook.io/rubydesurufurusukuratchibe/huan-jing-gou-zhu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
