搜索本站精品资源

本站所有资源均为高质量资源,各种姿势下载。

docker技术与php环境

作者 : 3214567959 文章热度:403

docker基础
1.安装docker

yum install -y docker
1
2.查看配置版本

docker version
1
3.docker基础操作

systemctl start docker # 启动docker
systemctl stop docker # 停止docker
systemctl status docker # 查看docker状态
systemctl restart docker # 重新启动docker
1
2
3
4
4.启动docker之前修改docker镜像源

vim /etc/docker/daemon.json

{
“registry-mirrors”: [“https://ftnejmh3.mirror.aliyuncs.com”]
}
1
2
3
4
5
5.启动docker服务。

systemctl restart docker
1
docker搭建nginx
1.查找 Docker Hub 上的 nginx 镜像,这里直接拉取官方的镜像

docker search nginx
1
2.拉取nginx的docker镜像

docker pull nginx
1
3.查看镜像列表

docker images
1
4.创建nginx配置

mkdir /docker/nginx

mkdir /docker/nginx/conf.d

mkdir /docker/nginx/conf.d/http

mkdir /docker/nginx/conf.d/tcp

#注意,此处创建的nginx.conf会覆盖docker容器默认的nginx.conf
#所以此处需要设置系统默认的配置信息,覆盖创建的目的是配置自定义的文件格式,引入nginx代理tcp的功能
vim /docker/nginx/nginx.conf

5.nginx.conf配置信息如下

user nginx;
worker_processes 1;

pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log warn;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /dev/null;
#access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;

#引入http配置文件
include /etc/nginx/conf.d/http/*.conf;
}

#引入tcp配置文件
stream {
include /etc/nginx/conf.d/tcp/*.conf;
}

6.http的配置模板
模板1

server {
listen 80;
listen [::]:80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.php;
location / {
}

location /api/test/ {
proxy_set_header Host $host; #防止nginx修改请求头的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-Port $http_port;
proxy_pass http://172.17.0.3:9000/;
}

}

模板2

server {
listen 9501;
listen [::]:9501;

server_name localhost;
root /docker/www;
index index.php index.html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /docker/www;
}

location /home {
index index.html index.php;
}

location ~ \.php$ {
root /docker/www/;
fastcgi_pass 172.17.0.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}

代理swoole-http项目

upstream swoole {
server 172.17.0.3:5200 weight=5 max_fails=3 fail_timeout=30s;
keepalive 16;
}

server {
listen 9509;
listen [::]:5200;
server_name localhost;
root /docker/www/lmrs/public;
index index.php index.html;

location / {
try_files $uri @laravels;
}

location @laravels {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header Server-Protocol $server_protocol;
proxy_set_header Server-Name $server_name;
proxy_set_header Server-Addr $server_addr;
proxy_set_header Server-Port $server_port;
proxy_pass http://swoole;
}
}

7.tcp的配置模板

upstream config-ssh {
hash $remote_addr consistent;
server 172.17.0.3:9501 weight=5 max_fails=3 fail_timeout=30s;
}
server {
#监听端口
listen 9501;
proxy_connect_timeout 10s;
#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_timeout 300s;
proxy_pass config-ssh;
}

8.创建nginx容器

#注意:此处若是想要用到其他端口,就需要映射指定的端口,默认给定 9501 – 9509
docker run -d –name nginx \
-p 80:80 -p 9501:9501 -p 9502:9502 -p 9503:9503 -p 9504:9504 -p 9505:9505 \
-p 9506:9506 -p 9507:9507 -p 9508:9508 -p 9509:9509 \
-v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /docker/nginx/conf.d:/etc/nginx/conf.d \
-v /docker/www:/docker/www \
–privileged=true nginx:latest

docker搭建php
1.先通过docker search php查找镜像,这里直接拉取官方的镜像,标签为7.4-fpm,其他版本的可自行选择

docker pull php:7.4-fpm
1
2.使用php镜像开启php-frm应用容器

docker run -p 9000:9000 -d –name php -v/docker/www:/docker/www –privileged=true php:7.4-fpm
1
3.查看php的docker地址

docker inspect php | grep “IPAddress”
1
4.nginx转发php代理

server {
listen 80;
listen [::]:80;
server_name localhost;
root /docker/www/lmrs-2008/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /docker/www/lmrs-2008/public;
}

location ~ \.php$ {
root /docker/www/lmrs-2008/public;
fastcgi_pass 172.17.0.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

docker 搭建mysql
1.先通过docker search mysql查找镜像,这里直接拉取官方的镜像

docker search mysql
1
2.拉取镜像

docker pull mysql
1
3.配置宿主机的mysql配置文件

vim /etc/my_docker.cnf
1
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
secure_file_priv=/var/lib/mysql
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

server-id=1
log-bin=mysql-bin
relay-log=relay-log

binlog_format=mixed

binlog_expire_logs_seconds = 600000
slow_query_log=1
slow-query-log-file=/usr/local/mysql/data/mysql-slow.log
long_query_time=3
early-plugin-load = “”
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 1
innodb_write_io_threads = 1

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

4.创建镜像容器

docker run -p 3306:3306 -d –name mysql \
-v /etc/my_docker.cnf:/etc/mysql/my.cnf –privileged=true \
-e MYSQL_ROOT_PASSWORD=root mysql
1
2
3
5.进入容器,连接mysql配置一个自己的用户,用于项目使用。(以下操做非必要)

create user `starsky`@`%` identified by “root”;

grant all on *.* to `starsky`@`%` with grant option;
1
2
3
docker搭建redis
1 . 创建redis文件

mkdir -p /docker/redis/data

mkdir -p /docker/redis/conf

touch /docker/redis/conf/redis.conf
1
2
3
4
5
2 . 拉取镜像

docker pull redis
1
3 .构建容器

docker run -p 6379:6379 –name redis -d redis \
-v /docker/redis/data:/data \
-v /docker/redis/conf/redis.conf:/etc/redis/redis.conf \
redis-server /etc/redis/redis.conf –privileged=true

1. 本站所有资源来源于用户上传和网络搜集,版权归原作者所有,如需商业用途或转载请与作者联系,因此不包含技术服务请大家谅解!
2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理!
3. 如用于商业或者非法用途,与本站无关,一切后果请用户自负!
4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
5.如有侵权请联系客服邮件3214567959@qq.com,我们会及时删除
A7站 » docker技术与php环境

发表评论

1886+

本站勉强运行

339+

用户总数

202+

资源总数

0+

今日更新

2024-3-18

最后更新时间

zh_CNChinese