How to expose in a network?

The below example is from the docker-compose docs.

From my understanding they want to have redis port 6379 available in the web container.

  • Custom fonts in rrdgraph in a Docker container running Alpine Linux
  • Call From quickstart.cloudera/172.17.0.2 to quickstart.cloudera:8020 failed on connection exception: java.net.ConnectException: Connection refused
  • Install node in Dockerfile?
  • Multiple service starting with make inside docker-compose
  • Dockerized Gitlab Container Backup
  • Docker for Mac Container to Host Networking - Consul Health Checks Connection Refused
  • Why don’t they have

    expose:
      - "6379"
    

    in the redis container?

    version: '2'
    services:
      web:
        build: .
        ports:
         - "5000:5000"
        volumes:
         - .:/code
        networks:
          - front-tier
          - back-tier
      redis:
        image: redis
        volumes:
          - redis-data:/var/lib/redis
        networks:
          - back-tier
    

  • CoreOS cluster installation alternatives (offline)
  • How to start docker container after succesfull wait-for-it script
  • Download S3 file to docker image in EBS
  • Docker, independent multiple rails instances
  • DC/OS on top of a docker container cluster
  • Containerizing a web application using Docker: copy source code to multiple images?
  • 2 Solutions collect form web for “How to expose in a network?”

    From the official Redis image:

    This image includes EXPOSE 6379 (the redis port), so standard
    container linking will make it automatically available to the linked
    containers (as the following examples illustrate).

    which is pretty much the typical way of doing things.

    Redis Dockerfile.

    You don’t need links anymore now that we assign containers to docker networks. And without linking, unless you publish all ports with a docker run -P, there’s no value to exposing a port on the container. Containers can talk to any port opened on any other container if they are on the same network (assuming default settings for ICC), so exposing a port becomes a noop.

    Typically, you only expose a port via the Dockerfile as an indicator to those running your image, or to use the -P flag. There are also some projects that look at exposed ports of other containers to know how to talk to them, specifically I’m thinking of nginx-proxy, but that’s a unique case.

    However, publishing a port makes that port available from the docker host, which always needs to be done from the docker-compose.yml or run command (you don’t want image authors able to affect the docker host without some form of local admin acknowledgement). When you publish a specific port, it doesn’t need to be exposed first.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.