Home>Article>Backend Development> Practical steps to install php environment with docker
This article introduces to you the actual steps of installing PHP environment with docker. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The following are the actual steps
//没有docker先安装 dockeryum -y install docker //启动 docker service docker start //拉取php+apache镜像 选择了fauria/lamp docker pull fauria/lamp //查看本地镜像 docker images /** 创建新容器 -p 端口映射,格式为:主机(宿主)端口:容器端口 -d 后台运行容器,并返回容器ID -v 主机的目录映射到容器的 格式为:主机目录:容器目录(多个可以一直往后加-v) 使用privileged=true,容器内的root拥有真正的root权限 最后一个参数使用的镜像名称 */ docker run -p 8081:80 -d -v /root/code/server:/var/www/project -v /root/data/apache2/:/etc/apache2/sites-available/ --privileged=true fauria/lamp
//查看运行中的容器 docker ps //进入id为2552开头的容器 docker exec -it 2552 bash //配置nginx反向代理 docker pull nginx //创建nginx容器 docker run -p 80:80 -d -v /root/data/nginx:/etc/nginx/conf.d --privileged=true nginx //nginx配置文件 server { listen 80; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass http://172.17.0.1:8081; } } //修改完重启这个容器,才会生效 //查看所有的容器包括未运行的 docker ps -a //开启一个容器 docker start a9ad //重启一个容器 docker restart s3ew //停止一个容器 docker stop 5d5d //删除一个容器 docker rm 3ef4 //docker-compose是用于方便管理docker容器的工具,用了会方便一点,不用也没错 //比如,容器已经创建了,但是需要修改挂载盘或开放更多端口, //这些操作只要更改yml文件,然后重新更新就好 //默认情况下文件命名为docker-compose.yml,进入当前目录下执行docker-compose命令就可以了 curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose --verison touch docker-compose.yml //docker-compose.yml中内容,注意格式 web1: image: 'nginx' restart: always ports: - '80:80' volumes: - '/root/data/nginx:/etc/nginx/conf.d'web2: image: 'fauria/lamp' restart: always ports: - '8081:80' volumes: - '/root/code/server:/var/www/project' - '/root/data/apache2/000-default.conf:/etc/apache2/sites-available/000-default.conf' //修改完文件执行这个更新操作 docker-compose up -d
Recommended related articles:
The above is the detailed content of Practical steps to install php environment with docker. For more information, please follow other related articles on the PHP Chinese website!