取り敢えずdockerでwebサイトを動かす
www_vtest このフォルダ内でコンテナの配置、コンテンツ、設定を管理する。
content_home HTML,php等サイトのコンテンツを入れておく。コンテナの配置する。
nginx nginxの設定フォルダ
default.conf nginxの設定
Dockerfile nginxのdockerの設定
php
Dockerfile phpのdockerの設定
docker-compose.yml dockerのコンテナの設定
ubuntuのSSHコンソールに入ってdocker-compose.yml
のあるフォルダに移動します。
で、nginx,phpコンテナをデタッチ(-d)バックグラウンドで実行(up)します。
# docker compose up -d
#cd /home/www_vtest
root@virtual-machine:/home/www_vtest# docker compose up -d
[+] Building 1.9s (10/10) FINISHED
=> [nginx internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 305B 0.0s
=> [nginx internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [nginx internal] load metadata for docker.io/library/nginx:1.23 1.8s
=> [php internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 109B 0.0s
=> [php internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [php internal] load metadata for docker.io/library/php:7.3.33-fpm 0.0s
=> CACHED [php 1/1] FROM docker.io/library/php:7.3.33-fpm 0.0s
=> [php] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:8782e6d00e27ab4288afd51760d9dcfc04d2a2895c337a6be73212edb5e40edd 0.0s
=> => naming to docker.io/library/www_vtest-php 0.0s
=> CACHED [nginx 1/1] FROM docker.io/library/nginx:1.23@sha256:f5747a42e3adcb3168049d63278d7251d91185bb5111d2563d58 0.0s
=> [nginx] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:803d7adf65458caa9fa844f11e99de734b77524c3afd1134ec34de0151f635ab 0.0s
=> => naming to docker.io/library/www_vtest-nginx 0.0s
[+] Running 3/3
? Network www_vtest_default Created 0.2s
? Container www_vtest-nginx-1 Started 0.9s
? Container www_vtest-php-1 Started
http://192.168.11.200:8085/index.php
にアクセスします。
が表示されれば成功!
content_home
の中身はコンテナの外にあるか確かめる。
www_vtest\content_home\hello.txt
を追加。
hello docker
を記入して保存。ブラウザで表示してみる。
OK!
www_vtest\docker-compose.yml dockerのコンテナの設定
version: "3"
services:
nginx:
build: ./nginx
ports:
- 8085:80
volumes:
- ./content_home:/usr/share/nginx/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
php:
build: ./php
volumes:
- ./content_home:/usr/share/nginx/html
www_vtest\nginx\default.conf nginxの設定
server {
listen 80;
listen [::]:80;
#server_name localhost;
server_name test.com;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
www_vtest\nginx\Dockerfile nginxのdockerの設定
FROM nginx:1.23
www_vtest\php\Dockerfile phpのdockerの設定
FROM php:7.3.33-fpm
www_vtest\content_home\index.php phpのinfo情報
<?
echo phpinfo();
?>