Home >Backend Development >PHP Problem >How to query the php port in docker in Centos
When running a Docker container on CentOS, you may need to query the port of the application running in the Docker container. For example, if you are running a web application written in PHP, you need to query the port number of PHP.
Here are the steps on how to query the PHP port on Docker on CentOS:
Running a Docker container
First, you need to run a Docker container on CentOS Install and run Docker containers on. You can install the Docker engine into your CentOS system using the following command:
sudo yum install docker-ce
After the installation is complete, run the following command to start the Docker engine:
sudo systemctl start docker
Now, you can start the Docker container on CentOS . For example, if you want to run a web application written in PHP in a container:
sudo docker run -d -p 8080:80 --name myphpapp php:apache
This command will run a web application on a PHP image with Apache as the web server in the container and add the Web The server's port 8080 is mapped to the host's port 80.
Query the port number of the Docker container
Once your container has started successfully, you can use the following command to query the port number of the web server in the Docker container:
docker ps
This will display a list of all Docker containers running on CentOS. You need to find the ID or name of the container you just started and query its details using the following command:
docker inspect <container_id or container_name>
This command will list the details of the container you selected. You'll want to look for the "Ports" section, which lists all open ports in the container, along with their mapped ports on the host. For example:
"Ports": { "80/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "8080" } ] },
This means that port 80 is opened in the container and mapped to port 8080 on the host.
Test port connection
Now that you know the port number of the application running in the container and its mapped port on the host, you can use The following command tests the port connection:
curl http://localhost:8080
This will return the homepage content of your web application running in the container. If you see the home page of the web application, it means the port connection is successful. If you receive a connection error, it is possible that the web application did not start correctly or that the port mapping is incorrect.
Summary:
It is not difficult to query the PHP port on Docker on CentOS. You just need to run the Docker container and query its details to get the port number and host port of your web application. You can then use the curl command to test the port connection to confirm that the application in your container is running correctly.
The above is the detailed content of How to query the php port in docker in Centos. For more information, please follow other related articles on the PHP Chinese website!