0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerチュートリアルやってみた(第2章コンテナ)その1

Last updated at Posted at 2018-07-10

前回 の続き。

Docker チュートリアル2章・・・に入る前に、

今朝やってみたら、docker infoがうまく動かない

$ docker info
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

コンテナが動くには、前提として、docker daemonが起動している必要がある。
Docker for macをまだ起動してなかっただけでした、てへぺろ。

第2章Container

どうやらDockerを最低限使いこなすにはこの3つの概念が必要なようだ。

  • Stack
  • Services
  • Container(今ここ)

Dockerfileを作る

ContainerをDockerfileなるもので定義する。

テキトーに作業フォルダに
Dockerfile をつくる。
ついでapp.py
requirements.txtも。

中身は読んでもあんまり理解できず。でもコピペして進む。

$ docker build -t friendlyhello .

ファイル名を間違えてるとここで怒られる。
でうまくいくと

...
Successfully built 8543f6131f0c
...

とかなんとか出てくる。

実行

$ docker run -p 4000:80 friendlyhello

なんかエラーでた

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
172.17.0.1 - - [10/Jul/2018 23:16:35] "GET / HTTP/1.1" 200 -
172.17.0.1 - - [10/Jul/2018 23:16:36] "GET /favicon.ico HTTP/1.1" 404 -

エラーじゃなくて警告(WARNING)だった。

チュートリアルどおり http:localhost:4000叩いたら
なんかhello worldでてきたよ!

スクリーンショット 2018-07-11 8.19.48.png
$ curl http://localhost:4000/

こっちは駄目でした。接続拒否される・・・と思ったら
同じターミナルでやろうとして、
docker-run-friendlyhelloをCtrl+Cで止めてたからでした。

別ターミナル開いてやるか、バックグラウンドで実行してからcurlすれば、、、

$ curl http://localhost:4000/
<h3>Hello World!</h3><b>Hostname:</b> 2b75bdad070c<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>[~]

見れました。
containerの終了の方法は

docker container ls

でcontainerIDを確認後、

docker container stop {さっきのID}

ってやるだけ。簡単ですね。

2章はまだ半分だけど今日はここまで。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?