Home > Backend Development > PHP Problem > How to query the php port in docker in Centos

How to query the php port in docker in Centos

PHPz
Release: 2023-03-24 17:22:02
Original
1379 people have browsed it

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:

  1. 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
    Copy after login

    After the installation is complete, run the following command to start the Docker engine:

    sudo systemctl start docker
    Copy after login

    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
    Copy after login

    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.

  2. 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
    Copy after login

    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>
    Copy after login

    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"
                 }
             ]
         },
    Copy after login

    This means that port 80 is opened in the container and mapped to port 8080 on the host.

  3. 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
    Copy after login

    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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template