31
28

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.

お気楽にnginxのDockerイメージを作ってみる

Posted at

nginxサーバのイメージを作ってみます。

設定ファイル

まず、ローカルに適当にディレクトリ作って以下のファイルを作ってください。

Dockerfile
FROM alpine:3.6

# nginxのインストール
RUN apk update && \
    apk add --no-cache nginx

# ドキュメントルート
ADD app /app
ADD default.conf /etc/nginx/conf.d/default.conf

# ポート設定
EXPOSE 80

RUN mkdir -p /run/nginx

# フォアグラウンドでnginx実行
CMD nginx -g "daemon off;"
default.conf
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /app;

        location / {
        }
}
app/index.html
<html>
<body>
TEST
</body>
</html>

イメージ作成

作ったディレクトリに移動して以下のコマンドでイメージ作れます。

docker build . -t original_alpine_nginx

イメージ確認

docker images
結果
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
original_alpine_nginx     latest              2bab041e0c34        6 minutes ago       6.44MB

コンテナ立ち上げ

docker run -d -p 80:80 --name sample_container original_alpine_nginx

動作確認

後始末

用が無くなったら消しましょう。

docker rm -f sample_container
docker rmi original_alpine_nginx
31
28
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
31
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?