温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Docker如何安装PHP

发布时间:2021-11-04 17:21:48 来源:亿速云 阅读:167 作者:柒染 栏目:建站服务器

本篇文章给大家分享的是有关Docker如何安装PHP,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

学习

方法一、docker pull php
查找Docker Hub上的php镜像


[root@huixuan nginx]# docker pull webdevops/php-nginx
Using default tag: latest
Trying to pull repository docker.io/webdevops/php-nginx ... 
latest: Pulling from docker.io/webdevops/php-nginx
1be7f2b886e8: Pull complete 
6fbc4a21b806: Pull complete 
c71a6f8e1378: Pull complete 
4be3072e5a37: Pull complete 
06c6d2f59700: Pull complete 
5c1c30789448: Pull complete 
42eeae6547fc: Pull complete 
3ff6b06497b0: Pull complete 
60c69a4834cc: Pull complete 
cbb835cfffc0: Pull complete 
604f67c351eb: Pull complete 
072984b59472: Pull complete 
943570e2b1d3: Pull complete 
1e35c99925af: Pull complete 
fbb001c74aae: Pull complete 
Digest: sha256:38b9e5a8072f83ae2e7ad47554f58c8ca4c4308adb3909070ad75deb761bb898
Status: Downloaded newer image for docker.io/webdevops/php-nginx:latest
[root@huixuan nginx]# 


使用webdevops/php-nginx镜像
运行容器
[root@huixuan nginx]# docker run -p 9000:9000 --name myphp -d webdevops/php-nginx
458820a216542e70d7deaac772713a5149f82be6d35c1e6aafdb5edd6e1ca97e
[root@huixuan nginx]# 

命令说明:
-p 9000:9000 :将容器的9000端口映射到主机的9000端口
--name myphp-fpm :将容器命名为myphp-fpm
-v ~/nginx/www:/www :将主机中项目的目录www挂载到容器的/www
-v $PWD/conf:/usr/local/etc/php :将主机中当前目录下的conf目录挂载到容器的/usr/local/etc/php
-v $PWD/logs:/phplogs :将主机中当前目录下的logs目录挂载到容器的/phplogs
查看容器启动情况

[root@huixuan nginx]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                     NAMES
458820a21654        webdevops/php-nginx   "/entrypoint super..."   46 seconds ago      Up 44 seconds       80/tcp, 443/tcp, 0.0.0.0:9000->9000/tcp   myphp
[root@huixuan nginx]# 

通过浏览器访问phpinfo()

PS:此处是通过nginx+php实现web服务,nginx配置文件的fastcgi_pass应该配置为webdevops/php-nginx容器的IP。
fastcgi_pass  172.17.0.4:9000;

容器IP的查方法
docker inspect 容器ID或容器名 |grep '"IPAddress"'

以上就是Docker如何安装PHP,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI