LoginSignup
2

More than 5 years have passed since last update.

1コマンドでローカルに簡易WEBサーバーを作る

Last updated at Posted at 2018-04-15

たまに静的サイトの出来を確認、テストするのにサクッとローカルにWEBサーバーを立てたい時があります。Macだと静的サイトであればfile:///でHTML,JSは動くんだけどやっぱサーバー上で動かさないと微妙に挙動に違いがありそうなので。。。

ローカル環境:MacOS High Sierra
WEBサーバー:Linux 4.9.60-linuxkit-aufs、Apache2.4

コマンド一発!

ローカルディレクトリを各々読み替えてくださいね〜

$ docker run -d -p 8080:8080 -v /Users/t-kajihara/work:/var/www/html centos/httpd-24-centos7

-vオプション:ローカルディレクトリとサーバーディレクトリをマウントする。
$ docker run -v [ローカルディレクトリ]:[サーバーディレクトリ]

-pオプション:コンテナのportとローカルホストのportを紐つける。
$ docker run -p [ローカルホストのport]:[サーバーのport]

-dオプション:デタッチドモードで起動する(コンテナ停止時に削除しない)
参考:デタッチド (-d)

http://localhost:8080/にアクセスする。

起動できた。
FireShot Capture 22 - Test Page for the Apache HTTP Server on Red Hat Ente_ - http___localhost_8080_-min.png

サーバーにログインする

まずコンテナIDを確認する。
$ docker ps | grep 'centos/httpd-24-centos7'

WEBサーバーにログインする。
$ docker exec -it [コンテナID] bash

Dockerありがたや〜〜

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