大网数据广告活动
服务器运维问答

Unexpected port 8080 on docker ps

· 52CE 我爱测

I use docker-compose up to start a container, and then use docker ps to display its info, I see the PORTS part is as below 0.0.0.0:2280->2280/tcp, 0.0.0.0:7000->7000/tcp, 8080/tcp the 8080 is unexpected. the image-building Docker…

问题原文

原帖链接 · lily · CC BY-SA 4.0

I use docker-compose up to start a container, and then use docker ps to display its info, I see the PORTS part is as below

0.0.0.0:2280->2280/tcp, 0.0.0.0:7000->7000/tcp, 8080/tcp

the 8080 is unexpected. the image-building Dockerfiles is:

    FROM tomcat
    MAINTAINER tol <[email omitted]>
    RUN apt-get update && apt-get install vim -y \
                && mkdir -p /data/appdatas/cat \
                && cd /usr/local/tomcat/webapps && rm -rf  docs  examples \
                && touch ~/.vimrc && echo "set mouse-=a" > ~/.vimrc && . ~/.vimrc
    COPY server.xml /usr/local/tomcat/conf
    COPY  datasource.xml  client.xml /data/appdatas/cat/
    COPY cat.war /usr/local/tomcat/webapps

there is no "8080" in server.xml, datasource.xml and client.xml, which are used in cat.war, so they are irrelevant

the docker-compose.xml is as below:

    version: "2"
    services:
      pica-cat3:
        container_name: pica-cat3
        image: pica-cat3:latest
        ports:
          - 7000:7000
          - 2280:2280
        volumes:
          - /opt/cat-logs:/data/applogs/cat
          - /root/cat3/datasource.xml:/data/appdatas/cat/datasource.xml
          - /root/cat3/client.xml:/data/appdatas/cat/client.xml
          - /root/cat3/server.xml:/usr/local/tomcat/conf/server.xml
        command: /bin/sh -c '/usr/local/tomcat/bin/catalina.sh run'

when I enter the container using docker exec -it CONTAINER_ID bash, and execute netstat -nlp, there is no 8080 either,

my question is, how is 8080 in the PORTS part?

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

It's inherited from the tomcat image.

You can check the Dockerfile for the tomcat image here, at the end you'll find:

EXPOSE 8080

Currently Docker has no mechanisms to disable or remove inherited exposed ports. There is an issue about that with an ongoing discussion since 2014 (!) in the Moby project issue tracker, which is related to Docker.

There is a workaround mentioned in that issue, using multistage builds:

FROM postgres as orig
FROM alpine:3.8 as postgres
COPY --from=orig / /
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]

However, this method has a downside:

[...] COPY --from=xxx ... would not preserve filesystem ownership, so you might want to be careful with that workaround.

It's up to you to decide if that workaround is usable for you. Personally, in your case, I'd just reuse the port 8080. You can map it to any port you like when you publish it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。