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

【CroWish勉強会】 Docker基礎

Last updated at Posted at 2020-03-04

#はじめに
勉強会を開催したのでまとめです。
https://crowish.connpass.com/event/166807/

#Dockerとnginxを使ってWebサーバーを構築する

// docker hubからnginxイメージを取得
$ docker pull nginx

// imageからコンテナを作成(80番から80番にポートフォワーディング)
$ docker run --name test_nginx -d -p 80:80 nginx

// コンテナが起動しているのかどうか確認
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
43305a573df9        nginx               "nginx -g 'daemon of…"   3 seconds ago       Up 2 seconds        0.0.0.0:80->80/tcp   test_nginx

http://localhost:80 にアクセスすると以下の画面がhyoujisareru
スクリーンショット 2020-02-14 21.54.29.png

##表示されるページを編集したい!

// コンテナを停止して削除
$ docker container rm `docker stop [container_id]`

/**
* コンテナを作成
* ホストのhtmlファイルをマウント
**/
$ docker container run --name test_nginx -v [表示したいhtmlがある絶対パス]:/usr/share/nginx/html -p 80:80 -d nginx

//nginxコンテナの中に入る
$ docker exec -it test_nginx /bin/bash 

// index.htmlの確認
root@43305a573df9:/# cat /usr/share/nginx/html/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Sample</h1>    
</body>
</html>

hennkousareteru
スクリーンショット 2020-02-14 22.06.06.png

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