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 3 years have passed since last update.

Docker入門(3)/忘備録(Nginxサーバを起動)

Posted at

Dockerデーモンをインストール
https://qiita.com/Uenrio/items/27355170e09da650cf48

Docker compose をインストール

$sudo curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Docker compose の実行権限を与える

$sudo chmod +x /usr/local/bin/docker-compose

インストール確認

$docker-compose --version
	docker-compose version 1.25.4, build 8d51620a

コンテナをインストールする。

$ vi docker-compose.yml

下記を記述。

docker-compose.yml
version: "3"
services:
    web-server:
        image: nginx:alpine
        ports:
            - "80:80"

$docker-compose up -d

※-dオプションをつけるとバックグラウンドで実行する

Pulling web-server (nginx:alpine)...
alpine: Pulling from library/nginx
4167d3e14976: Pull complete
bb292c78f105: Pull complete
Digest: sha256:abe5ce652eb78d9c793df34453fddde12bb4d93d9fbf2c363d0992726e4d2cad
Status: Downloaded newer image for nginx:alpine
Creating docker-practice_web-server_1 ... done

成功!

立てたサーバーにアクセスした後にログを確認
http://localhost/
https://gyazo.com/dbfe9880c40be3ccfd4ba020565340de
上リンクのようなページが表示されれば完了!

$docker logs docker-practice_web-server_1 -f

※docker-practice_web-server_1はコンテナ名

アクセスした結果のログ

192.168.176.1 - - [10/Apr/2020:04:10:55 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
192.168.176.1 - - [10/Apr/2020:04:10:55 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
2020/04/10 04:10:55 [error] 7#7: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.176.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"
192.168.176.1 - - [10/Apr/2020:04:11:59 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"

構築完了!

コンテナを落としたい時

$ docker-compose down

(自動でコンテナも消してくれる)
当然、 http://localhost/
にアクセスしてもページは表示されない

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?