How to expose UDP ports in the Docker-Compose configuration file?

Asked

Viewed 324 times

2

I have the following file docker-compose.yml and would like to expose some of the doors as UDP.

version: "3.0"
services: 
  myservice: 
    image: "my/service"
    ports: 
      - "40061:4061"
      - "40062:4062"
      - "5684:5684" <--- UDP
      - "5683:5683" <--- UDP
  mongo: 
    image: "mongo:3.4"

It seems that the default is to expose these ports as TCP, so the external service is not accessing.

How the Docker-Compose configuration would look so that it was possible to expose these ports as UDP?

1 answer

1


To expose the port as UDP, simply add at the end of the mapping /udp. Using his commie as an example, we would have this:

version: "3.0"
services: 
  myservice: 
    image: "my/service"
    ports: 
      - "40061:4061"
      - "40062:4062"
      - "5684:5684/udp"
      - "5683:5683/udp"
  mongo: 
    image: "mongo:3.4"

When we check the status of services with Docker-Compose ps we’d see the doors as UDP, something like that:

Name                     Command                  State         Ports           
--------------------------------------------------------------------------------------------
dockerudp_mongo_1        docker-entrypoint.sh     Up            27017/tcp                 
                         mongod                                                            
dockerudp_myservice_1    /bin/sh -c whatever.sh   Up            0.0.0.0:40061->4061/tcp,  
                                                                0.0.0.0:40062->4062/tcp,  
                                                                0.0.0.0:5683->5683/udp,   
                                                                0.0.0.0:5684->5684/udp

It is important to remember that in your image, the my/service constructed, shall also have the doors exposed as UDP, that is, shall contain an instruction such as this:

EXPOSE 5683/udp 5684/udp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.