Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (29.3k points)

I'm trying to set up a dev environment for my project.

I have a container (ms1) that should be put in his own network ("services" in my case), and a container (API gateway) that should access that network while exposing an HTTP port to the host's network.

Ideally, my docker compose file would look like this:

version: '2'

services:

    ms1:

        expose:

            - "13010"

        networks:

            services:

                aliases:

                    - ms1

   apigateway:

        networks:

            services:

                aliases:

                    - api

        network_mode: "host"

networks:

    services:

docker-compose doesn't allow to use of network_mode and networks at the same time.

Do I have other alternatives?

At the moment I'm using this:

apigateway:

        networks:

            services:

                aliases:

                    - api

        ports:

            - "127.0.0.1:10000:13010"

and then the apigateway container listens on 0.0.0.0:13010. It works but it is slow and it freezes if the host's internet connection goes down.

Also, I'm planning on using vagrant in the future upon docker, does it allow to solve in a clean way?

1 Answer

0 votes
by (50.2k points)

The simple way which I would prefer is 

1. Find the host network docker network ls

2. Use this DockerCompose file

  services:

          ms1:

              ports:

                  - "13010"

              networks:

                  - service

          apigateway:

              networks:

                  - front

                  - service

    networks:

          front:

          service:

              external:

                  name: "<ID of the network>"

This way is the simplest and able to get an answer. I hope it helps.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...