Docker compose port mapping

后端 未结 4 1310
别跟我提以往
别跟我提以往 2020-12-13 01:56

I have a docker-compose yml file as in below

version: \'2\'
services:
  nodejs:
    build:
      context: .
      doc         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 02:11

    If you want to bind to the redis port from your nodejs container you will have to expose that port in the redis container:

    version: '2'
    services:
      nodejs:
        build:
          context: .
          dockerfile: DockerFile
        ports:
          - "4000:4000"
        links:
          - redis
    
      redis:
        build:
          context: .
          dockerfile: Dockerfile-redis
        expose:
          - "6379"
    

    The expose tag will let you expose ports without publishing them to the host machine, but they will be exposed to the containers networks.

    https://docs.docker.com/compose/compose-file/#expose

    The ports tag will be mapping the host port with the container port HOST:CONTAINER

    https://docs.docker.com/compose/compose-file/#ports

提交回复
热议问题