LoginSignup
2
9

More than 5 years have passed since last update.

[社内向け]Docker勉強会(入門)

Last updated at Posted at 2017-04-24

Dockerってなによ?

@IT 超入門Docker:第1回 Dockerとは 参照

Dockerで開発してみる

ローカルにDockerを導入する

ほかにもあるけどこの辺がおそらく主流

とりあえずDockerでHello world!

$ docker container run hello-world

なにが起こったの?

  1. Docker Hubからhello-worldのイメージをダウンロード(docker image pull)
  2. hello-worldイメージをフォアグラウンドで実行

hello-worldイメージはなにをしているのか見てみよう

Dockerfileを見てみるとわかります

これを踏まえて開発の流れ

  1. ベースイメージを決める
  2. Dockerfileを作成する
  3. Dockerfileを元にイメージをbuild(docker image build)
  4. buildしたイメージをデプロイ(実行)

(ベースイメージ内で作業した内容をcommitする方法もあるけどアンチパターンだと思う)

golangでhello-worldしてみよう

1. ベースイメージを決める

golangの公式イメージ(golang:1.7.5)を使用することにします。
当然、まっさらなイメージを選択して自分でgolangのインストールから実施するのもOKです。

2. Dockerfileを作成する

FROM golang:1.7.5
COPY hello-world.go /src/
RUN go build /src/hello-world.go && rm /src/hello-world.go
ENTRYPOINT ./hello-world
hello-world.go
package main
import "fmt"
func main() {
  fmt.Printf("Hello world\n")
}

3. Dockerfileを元にイメージをbuild

$ docker image build . -t dockertest:1.0

4. buildしたイメージをデプロイ(実行)

$ docker container run dockertest:1.0

Dockerfile書き始める前に色々試したい

ベースイメージでbashを実行して作業しましょう。

$ docker container run -it --rm golang:1.7.5 /bin/bash

とりあえず今日はこのあたりまで。指摘とかあったら修正します。
次回(あるのか!?)はコンテナ間の通信について、とかかな。

2
9
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
2
9