

According to the configurations you can simply define any number of ports you. This label comes under port configuration in your deployment. In Kubernetes you can define your ports using port label.

This would direct all requests to to the web app running in the first Docker container and all requests to to the second Docker container. This port mapping is what effectively makes the containers web service accessible from external sources (via the Docker hosts IP address on port 8080). If a specific NodePort is not specified, a port from a range configured on the Kubernetes cluster (default: 30000-32767) will be picked at random. Instead, Docker and other container managers make it easy to map ports between the host OS and the container. While you could certainly modify each container or run-command to bind the container's service to a unique host port, this quickly becomes a hassle at scale. Then you can configure an Nginx sconfiguration that looks something like this: upstream app-a By default, each wants to bind to port 5432 as its default.
#DOCKER PORT MAP UPDATE#
Bind them to a random port on the local host: docker run -d -p 127.0.0.1:3000:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUNDĭocker run -d -p 127.0.0.1:5000:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND To update Docker regarding the ports that the container listens on, the parameter ‘EXPOSE’ can be set in Dockerfile: EXPOSE Expose Docker port to a single host interfacey default, the ‘-p’ flag will bind the specified port to all the network interfaces on the host machine. If no hostPort is specified, Docker will automatically allocate one. One way to get around this would be to set up an Nginx reverse proxy in front of the containers.įor example, say you have two different app. Expose a port at runtime, but not create any mapping to the host-p: Create a port mapping rule like -p ip:hostPort:containerPort. Though when you are running multiple app that you can’t have them all listen on the same port. The most basic way to expose a web app running in a Docker container to the outside is to bind port 80 in the container to port 80 on the host system: docker run -d -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
