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.

  • How Spring Cloud relates to Docker Swarm
  • Access Wildfly-Docker-Container from Apache-Docker-Container
  • How can i mount /dev/shm in a docker container
  • Debug Symfony2 in Docker with PhpStorm and Xdebug
  • docker-compose start “ERROR: No containers to start”
  • Docker: MySQL-Socket created with wrong permissions when bind-mounted from host to container
  • 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
    

  • Getting error after installing docker toolbox on windows. Error: connect ECONNREFUSED 10.0.75.2:2375
  • Docker: Creating a data volume container vs simply using the -v flag with `run`?
  • dockerize django apache developer environment
  • Container with app + DB
  • docker-compose: difference between network and link
  • How to connect to a MySQL Docker Container via SSH?
  • 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.