1

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 <etol@126.com>
    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?

lily
  • 165
  • 1
  • 7

1 Answers1

2

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.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79