1
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 1 year has passed since last update.

Dockerで任意のフォルダをマウントする

Last updated at Posted at 2024-03-15

はじめに

前回の「Windows上にDocker環境を構築する」に続いて、Dockerのコンテナに任意のフォルダをマウントする方法を備忘録としてまとめてみました。

イメージのダウンロード

  • 前回の記事と同じく、httpdというイメージを利用します。
PowerShell
PS> docker pull httpd

コンテナの作成と実行

  • 前回は以下のコマンドを実行しましたが、これにパラメーターを加えて任意のフォルダをマウントします。
前回のコマンド
PS> docker run --name httpd_test -p 10088:80 -it httpd
  • 任意のフォルダをマウントする際は、--mount type=bind,source={マウント元},target={マウント先}というオプションを付けます。
    • 今回はホストのD:\testフォルダを、コンテナの/usr/local/apache2/htdocsにマウントしています。
  • なおDockerの公式リファレンスでは、「新しいユーザは --mount 構文を使うべきです。経験のあるユーザは -v や --volume 構文に慣れているでしょうが、調査によって、より簡単に利用できると分かっている --mount の利用を推奨します。」 と書かれているので、今回はそれに従いました。
任意のフォルダをマウントする際のコマンド
PS> docker run --name httpd_test -p 8888:80 -it --mount type=bind,source=D:\test,target=/usr/local/apache2/htdocs httpd

参考URL

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