I hope you can help.
I had an old docker image that was configured for networking exposing port 8082. I am using this image as my base image to created a new container but I can't seem to get rid of the old networking settings. The 8082 ports are not specified in my new Dockerfile or docker-composer file but it still comes up. My new port is 8091.
server@omv:~/docker/app$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f023f6a0a792 api_app_image "/entrypoint.sh" 3 minutes ago Up 3 minutes 80/tcp, 8082/tcp, 0.0.0.0:8091->8091/tcp api_app
Here is my docker-composer file.
api_app:
container_name: api_app
build:
context: ./api
dockerfile: Dockerfile
ports:
- "8091:8091"
volumes:
- ./api/app:/var/www/html/apiapp
Here is a snip from my Dockerfile
FROM bde8c3167970
VOLUME /etc/nginx/conf.d
VOLUME /var/www/html/apiapp
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 80 8091
Thanks, any help would be appreciated.
There is no Dockerfile option to remove a port that's been set with
EXPOSE
, and it is always inherited by derived images; you can't remove this value.However:
In modern Docker simply having a port "exposed" (as distinct from "published") means almost nothing. It shows up in the
docker ps
output as unmapped, and if you use thedocker run -P
option to publish all exposed ports, it will be assigned an arbitrary host port, but that's it. There's no harm to having extra ports exposed.Since each container runs in an isolated network namespace, there's no harm in using the same port in multiple containers. The container port doesn't have to match the host port. If the base image expected to run the application on port 8082, I'd keep doing that in the derived image; in the Compose setup, you can set
ports: ['8091:8082']
to pick a different host port.