如何在Rocky Linux 9.4中通过Docker部署LNMP架构?_ ?-灵析社区

通了顺畅了

我在rozkylinux9.4版本中用docker 做一个lnmp,但是期间一直出现很多的问题不知道从哪里下手,希望有大佬能抽点时间给我做一个详细的步骤,我是在培训机构学习的,![这是我的考试题](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240922/55e1671193b2e5dff4a54aaf7bb64337.png) 就是第四道题,老师的要求是如图片所说,希望有哥能给我引导下,是分离部署的lnmp架构并且RR轮询老师的要求....,有大佬给我解答我加V出大洋请哥喝几瓶劲酒 我用pull所需要的容器但是里面的bash不支持很多的命令,而且文件的路径也和我之前所学习的路径有很多不一样的地方 然后我还用dockerfile也试试了,最后我访问回环地址报错404但是加上端口号就能出现nginx的welcome to nginx,换另外一个容器的端口号也是可以成功的,但只我不知道怎么排错,一片迷茫 [root@localhost ~]# ls /php/ check_db.php Dockerfile php-8.2.7.tar.gz [root@localhost ~]# ls /root/mysql/ Dockerfile mysql.sh my.cnf Percona-Server-8.0.32-24-Linux.x86_64.glibc2.34.tar.gz [root@localhost ~]# ls /root/nginx check_db.php default.conf Dockerfile nginx-1.25.3.tar.gz 上面是我的各个容器的dockerfile的存放路径,尝试的结果就是如我所说报错404,我现在目前是认为链接上出现了问题导致不能连接php页面但是用dockerfile做的太头疼了,还是从网络找的步骤太。。。。一言难尽,向寻求大佬能用pull下来的镜像完成第四题,欢迎大佬来挑战,若能有大佬给我解答我加V出大洋请哥喝几瓶劲酒

阅读量:174

点赞量:0

问AI
基于你的描述,你应该不用折腾dockerfile去构建镜像。 这里给你一个docker compose的方式。 version: '3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress nginx: image: nginx:latest ports: - "80:80" volumes: - ./app:/usr/share/nginx/html - ./nginx.conf:/etc/nginx/nginx.conf restart: always php: image: php:7.4-fpm volumes: - ./app:/var/www/html restart: always volumes: db_data: 这个"docker-compose.yml"文件中,定义了三个服务:db(MySQL)、nginx和php(PHP-FPM)。定义了一个卷db_data,用于存储MySQL的数据。 其中 "./app"是指"docker-compose.yml"这个文件目录下的app文件夹,这是你Web应用程序目录,把你的php文件放这。 还要创建一个Nginx配置文件nginx.conf,配置Nginx代理请求到PHP-FPM服务: worker_processes 1; events { worker_connections 1024; } http { upstream php { server php:9000; } server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include fastcgi_params; fastcgi_pass php; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } } 在你的"docker-compose.yml"文件目录执行这个命令启动服务,会自动解析"docker-compose.yml"文件,拉取镜像并启动容器,一步完成。 docker-compose up -d 不知道你是否熟悉docker-compose,每个参数跟你使用docker run 基本能对应上。你可以继续对照着使用docker run挨个创建容器也是一样的。这里为了更直观我用docker-compose.yml文件方式提供。