Table of Contents
Debian + Docker Swarm + Container
Debian + Docker Compose
root@web:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 13ee0aae751b mariadb "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp root_db_1 14sd00drg3gr php7:fpm "docker-php-entryp…" About a minute ago Up About a minute 9000/tcp sui-php 25dcw4ht220a nginx "/usr/sbin/nginxctl…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp root_web_1
docker-compose.yml
version: "3" services: nginx: restart: unless-stopped image: nginx:latest container_name: nginx networks: - mynet ports: - 80:80 - 443:443 php70: image: php:7.0-fpm container_name: php70 restart: unless-stopped networks: - mynet volumes: - ./projects:/projects networks: mynet: external: true
Nginx configuration
server { index index.php index.html; server_name php-docker.local; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /code; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php70:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } }
Create volumes for WordPress
# docker volume create --name wordpress_data # docker run -d --name wordpress \ -p 8080:80 -p 8443:8443 \ --env ALLOW_EMPTY_PASSWORD=yes \ --env WORDPRESS_DATABASE_USER=bn_wordpress \ --env WORDPRESS_DATABASE_PASSWORD=******* \ --env WORDPRESS_DATABASE_NAME=rock007_wordpress \ --network wordpress-network \ --volume wordpress_data:/rock007/wordpress \ bitnami/wordpress-nginx:latest
nginx reverse proxy
add_header X-Frame-Options SAMEORIGIN; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_hide_header X-Frame-Options;
net cluster
root@web:~# docker service ps swarm_cluster ID NAME IMAGE NODE DESIRED STATE CURRENT STATE bdjrhe896xye swarm_cluster.1 wordpress_server:latest node02.stps.tn.edu.tw Running Running about a minute ago fcq9es71z8zf swarm_cluster.2 drupal_server:latest node01.stps.tn.edu.tw Running Running about a minute ago xghvm62h2o4x swarm_cluster.3 apache2_server:latest node03.stps.tn.edu.tw Running Running 7 seconds ago
docker stats
#docker stats --no-stream CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS f21a35e99e00 0.06% 2.325 GiB / 15.26 GiB 15.33% 559.7 kB / 465.6 kB 565.9 MB / 589.8 kB 0 a0f6f6adcb13 0.03% 2.173 GiB / 15.26 GiB 14.75% 5.785 MB / 5.968 MB 589 MB / 23.67 MB 0 aeaeb46910ad 0.00% 80.13 MiB / 15.26 GiB 0.53% 384.8 kB / 66.88 kB 161.9 MB / 237.6 kB 0 bf6192f34bf9 0.00% 14.17 MiB / 15.26 GiB 0.14% 901 kB / 984.7 kB 162.7 MB / 0 B 0
結論
1.遇到非預期停電,這些containers花費很多時間reboot,最好有UPS與RAID 0+1
2.這台1U DELL屬低階伺服器,且風扇太吵考慮停用,未來改桌上型PC做docker意義不大
3.目前工作環境不需要做負載平衡,一台Debian就綽綽有餘