Solve the problem of WARNING: Published ports are discarded when using host network mode

Solve the problem of WARNING: Published ports are discarded when using host network mode

Problem Description

When creating a docker container, the following warning message is prompted:

aaa$ sh start.sh
WARNING: Published ports are discarded when using host network mode

My steps to create a container start.sh are as follows:

docker run -i -t \
--name ai-tomcat \
--network host \
-p 10707:10707 \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-v /home/xxx/application/tomcat/logs:/home/tomcat/logs \
--restart=always \
-e JAVA_OPTS="-Xms4096m -Xmx4096m -Dspring.application.nacos-server-addr=10.192.0.100:8848" \
-d ai-tomcat:v1.0.5

The focus is on the following two lines:

--network host \
-p 10707:10707 \

operating environment

  • Ubuntu 18.04 LTS
  • Docker version 20.10.2, build 2291f61

Solution

error analysis

  • 1. View the image
    and enter the command:
docker images -a

Output result:

REPOSITORY                                              TAG                            IMAGE ID       CREATED         SIZE
ai-tomcat                                               v1.0.5                         d94ef52e7d2c   2 weeks ago     434MB
<none>                                                  <none>                         89e7631debd3   2 weeks ago     434MB
<none>                                                  <none>                         58476b194d65   2 weeks ago     434MB
<none>                                                  <none>                         dd5e60428f55   2 weeks ago     434MB
<none>                                                  <none>                                       ad1150fec7ae   2 weeks ago     434MB
  • Found the problem: there is a mirror with the same size and creation time as the mirror ai-tomcat:v1.0.5
  • Cause of the problem: It should be an exception caused by a syntax problem when the Dockerfile creates the container. Let's ignore that here.
  • 2. Determine whether the port is occupied
tcp        0      0 0.0.0.0:31706           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:31707           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:10012           0.0.0.0:*               LISTEN      -
tcp6       0      0 :::31711                :::*                    LISTEN      -
tcp6       0      0 :::18080                :::*                    LISTEN      -
tcp6       0      0 :::31713                :::*                    LISTEN      -
tcp6       0      0 :::2049                 :::*                    LISTEN      -
tcp6       0      0 :::10050                :::*                    LISTEN      -
tcp6       0      0 :::54563                :::*                    LISTEN      -
tcp6       0      0 :::31716                :::*                    LISTEN      -
tcp6       0      0 :::31717                :::*                    LISTEN      -
tcp6       0      0 :::9253                 :::*                    LISTEN      -
tcp6       0      0 :::9253                 :::*                    LISTEN      -
tcp6       0      0 :::10707                :::*                    LISTEN      -

Found that port 10707 is already in use.

problem solving steps

  • 1. First delete the created container

Delete container:

docker stop ai-tomcat
docker rm ai-tomcat
  • 2. Modify the script start.sh
docker run -i -t \
--name ai-tomcat \
--network bridge \
-p 20707:10707 \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-v /home/xxx/application/tomcat/logs:/home/tomcat/logs \
--restart=always \
-e JAVA_OPTS="-Xms4096m -Xmx4096m -Dspring.application.nacos-server-addr=10.192.0.100:8848" \
-d ai-tomcat:v1.0.5

Key points:
[1] Modify --network host to --network bridge
[2] Modify port 10707 to 20707 (make sure port 20707 is not occupied)

  • 3. Run the script start.sh to recreate the container
start.sh

The WARNING: Published ports are discarded when using host network mode error was not prompted after the container was created.

The problem is basically solved here.

reference

  1. https://blog.csdn.net/tilyp/article/details/103371360
  2. 22 common commands for Docker
  3. Dockerfile summary: common instructions, precautions, common errors (no such file or directory, Permission denied)

Guess you like

Origin blog.csdn.net/zengNLP/article/details/127220244