Docker(Nginx Container) on Amazon Linux 2

環境構築

$ yum install -y docker
$ systemctl enable docker
$ systemctl start docker

Nginx Container

Container用ディレクトリ作成/移動

$ mkdir docker-nginx
$ cd docker-nginx/

ドキュメントルート作成/サンプルHTML作成

$ mkdir htdocs
$ vim htdocs/index.html
$ cat htdocs/index.html
docker test

Dockerfile作成/ビルド

$ vim Dockerfile
$ cat Dockerfile
FROM nginx
COPY htdocs /usr/share/nginx/html
$ docker build -t nginx-sample .

Docker実行/動作確認

$ docker run --name nginx-sample-1 -d -p 8081:80 nginx-sample
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
84729b265263        9a60da8e4e60        "/docker-entrypoint.…"   6 days ago          Up 1 minutes        0.0.0.0:8081->80/tcp   nginx-sample-1
$ curl http://localhost:8081
docker test
$ docker logs 84729b265263
/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: IPv6 listen already enabled
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.17.0.1 - - [19/Dec/2020:14:28:02 +0000] "GET / HTTP/1.1" 200 12 "-" "curl/7.61.1" "-"