3
4

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 Apacheサーバー(httpd)+バインドマウント

Last updated at Posted at 2018-12-03

Docker初級
Apacheサーバーを簡単にローカルに立てて作成中のサイトなどをブラウザで確認できる。
サーバー環境とhtmlソースを別に管理できるので便利。

Dockerをインストール(Mac)
https://docs.docker.com/docker-for-mac/install/

Apacheサーバー(httpd)を立て、別ディレクトリにあるhtmlを表示する

$ docker run -d -p 8080:80 -v [htmlファイルのパス]:/usr/local/apache2/htdocs/ httpd

(カレントディレクトリにあるhtmlをマウントする場合)

$ docker run -d -p 8080:80 -v "$(PWD)":/usr/local/apache2/htdocs/ httpd

ブラウザからアクセスする
http://localhost:8080/

コンテナ停止

$ docker stop [コンテナ識別子]

docker コマンド

$ docker run イメージ取得、コンテナ生成、コンテナ起動を一度に行う

docker run のオプション

-d, --detach
Run container in background and print container ID
バックグラウンドでコンテナを実行し、コンテナIDを表示する 

-p, --publish=[]
Publish a container’s port(s) to the host
コンテナのポートをホストに割り当てる
(例)-p 8080:80 ホストのポート8080をコンテナのポート80に割り当てる

-v, --volume
Bind mount a volume
ボリュームをコンテナに連結して認識させる
[ホストのディレクトリ]:[コンテナのディレクトリ]

Use bind mounts
https://docs.docker.com/storage/bind-mounts/

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?