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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Four ways to exit Docker container: Use Ctrl D in the container terminal Enter exit command in the container terminal Use docker stop <container_name> Command Use docker kill <container_name> command in the host terminal (force exit)

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to restart the Docker container: get the container ID (docker ps); stop the container (docker stop <container_id>); start the container (docker start <container_id>); verify that the restart is successful (docker ps). Other methods: Docker Compose (docker-compose restart) or Docker API (see Docker documentation).

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).
