LoginSignup
0
0

More than 1 year has passed since last update.

【Docker】apacheイメージで静的ページを表示させる

Last updated at Posted at 2022-12-18

Dockerfileを作成

FROM httpd:latest
COPY ./index.html /usr/local/apache2/htdocs/
EXPOSE 80
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>hello!</title>
    </head>
    <h1>hello!</h1>
</html>

コンテナ作成

イメージ作成

docker build -t apache_page ./

コンテナ作成+起動

docker run -p 80:8080 --name apache_page -d -it --rm apache_page bash

-p ポート番号を割り当てる。
-d バックグラウンドでコンテナを起動する

localhost:8080にアクセス

スクリーンショット 2022-12-18 9.34.38.png

ページが表示されることを確認。

docker-compose.ymlで作成

docker-composeを使うと、さらに簡単に構築できる。

docker-compose.yml
version: '3'

services:
  apache_page:
    platform: amd64 # M1 Macを使用時、コンテナがうまく動作しない時に指定
    ports:
      - "127.0.0.1:8080:80"
    build:
      context: .
      dockerfile: Dockerfile

コンテナ起動
docker-compose up -d

curl
curl localhost:8080

以下のレスポンスが返って来ればOK

<!DOCTYPE html>
<html>
    <head>
        <title>hello!</title>
    </head>
    <h1>hello!</h1>
</html>

参考・関連記事

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