ファイルを保存するには Ctrl+O を押してから Enter を押し、nano を終了するには Ctrl+X を押します。
HTML コンテンツの作成
html ディレクトリとシンプルな index.html ファイルを作成しましょう。
mkdir -p html
nano html/index.html
エディタに以下の HTML コンテンツを追加します。
<!DOCTYPE html>
<html>
<head>
<title>Docker Compose Test</title>
</head>
<body>
<h1>Docker Compose is working!</h1>
<p>
If you can see this page, you have successfully resolved the
docker-compose issue.
</p>
</body>
</html>
ファイルを保存するには Ctrl+O を押してから Enter を押し、nano を終了するには Ctrl+X を押します。
Docker Compose プロジェクトの実行
次に、Docker Compose プロジェクトを実行しましょう。
docker compose up -d
-d フラグは、コンテナをデタッチドモード(バックグラウンドで)で実行します。
以下のような出力が表示されるはずです。
Creating network "docker-compose-test_default" with the default driver
Creating docker-compose-test_web_1... done
これは、Docker Compose が正常にコンテナを作成して起動したことを示しています。
ウェブサーバーの検証
ウェブサーバーが正常に動作していることを検証しましょう。
curl http://localhost:8080
先ほど作成した HTML コンテンツが表示されるはずです。
<!DOCTYPE html>
<html>
<head>
<title>Docker Compose Test</title>
</head>
<body>
<h1>Docker Compose is working!</h1>
<p>
If you can see this page, you have successfully resolved the
docker-compose issue.
</p>
</body>
</html>
ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint: Bind for 0.0.0.0:8080 failed: port is already allocated
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy