LoginSignup
0
0

More than 1 year has passed since last update.

VirtualBox+Ubuntu20.04+Docker+nginx

Last updated at Posted at 2023-01-08

Dockerでホストとコンテナでフォルダ共有(ボリューム設定)を試してみようと思ってWebサーバーを起動してみたら、そもそもVirtualBoxのホストOSから見れるような設定をしていなかった。

環境

VirtualBox6.1
ホストOS: Windows10 Home 20H2
ゲストOS: Ubuntu20.04 + Docker20.10.22 + nginx1.23.3

Dockerでnginxコンテナを起動

docker run --name mynginx -p 8080:80 nginx

nacanaca@dmin-VirtualBox:~/dockertest/DockerFileBase$ docker run --name mynginx -p 8080:80 nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/01/08 08:46:45 [notice] 1#1: using the "epoll" event method
2023/01/08 08:46:45 [notice] 1#1: nginx/1.23.3
2023/01/08 08:46:45 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2023/01/08 08:46:45 [notice] 1#1: OS: Linux 5.15.0-57-generic
2023/01/08 08:46:45 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/01/08 08:46:45 [notice] 1#1: start worker processes
2023/01/08 08:46:45 [notice] 1#1: start worker process 29
2023/01/08 08:46:45 [notice] 1#1: start worker process 30

start worker process 30でプロンプトが戻ってこないので失敗したのかと思ったらこの状態で大丈夫でした…。

" ブラウザで確認
localhosut:8080

VirtualBox_Ubuntu20.04_Docker_nginx.png

ホストOS(Windows10)から確認

と、ここで、ん?ゲストOSのIPアドレスって?
そもそも見れるように設定が必要なのでは?と気付く。

今後、試しながら、加筆予定。

VirualBox → 設定 → ネットワーク → アダプター1タブ
高度 → ポートフォワーディング

名前:HTTP(任意)
プロトコル:TCP
ホストIP:空欄
ホストポート:8080(任意:0から1023以外)
ゲストIP:空欄
ゲストポート:8080(dockerでnginx起動時に指定したポート)

Windows10のブラウザで確認
localhosut:8080

参考にしたサイト

他のPCやスマホからVirtualBox(ゲストOS)のWebサーバに接続する
https://qiita.com/OharanD/items/bcf5cff7096179641691

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