how can I communicate between containers?












1















Im using a container with api gateway in port 80, and I'm needing communicate the api gateway between another containers (all these one using dockerfile and docker-compose). How can I do these others conteiners not expose the port to localhost but communicate internally with the api gateway?



My docker-compose:



version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "3000:3000"


Solution:



Changed docker-compose file to:



version: '3.5'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
expose:
- "3000"
image: api-name-service
container_name: api-name-service
networks:
- api-network

networks:
api-network:
name: api-network-service


When the services is in the same network, this services can communicate with service name, like "http://api-name-service:3000".










share|improve this question

























  • I'm not quite sure what you're asking--could you try to rephrase the question?

    – duhaime
    Nov 18 '18 at 1:58











  • Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

    – Titao Yamamoto
    Nov 18 '18 at 2:05











  • Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

    – duhaime
    Nov 18 '18 at 2:14











  • @duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

    – Titao Yamamoto
    Nov 18 '18 at 2:30






  • 1





    But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

    – gasc
    Nov 18 '18 at 3:10
















1















Im using a container with api gateway in port 80, and I'm needing communicate the api gateway between another containers (all these one using dockerfile and docker-compose). How can I do these others conteiners not expose the port to localhost but communicate internally with the api gateway?



My docker-compose:



version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "3000:3000"


Solution:



Changed docker-compose file to:



version: '3.5'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
expose:
- "3000"
image: api-name-service
container_name: api-name-service
networks:
- api-network

networks:
api-network:
name: api-network-service


When the services is in the same network, this services can communicate with service name, like "http://api-name-service:3000".










share|improve this question

























  • I'm not quite sure what you're asking--could you try to rephrase the question?

    – duhaime
    Nov 18 '18 at 1:58











  • Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

    – Titao Yamamoto
    Nov 18 '18 at 2:05











  • Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

    – duhaime
    Nov 18 '18 at 2:14











  • @duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

    – Titao Yamamoto
    Nov 18 '18 at 2:30






  • 1





    But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

    – gasc
    Nov 18 '18 at 3:10














1












1








1








Im using a container with api gateway in port 80, and I'm needing communicate the api gateway between another containers (all these one using dockerfile and docker-compose). How can I do these others conteiners not expose the port to localhost but communicate internally with the api gateway?



My docker-compose:



version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "3000:3000"


Solution:



Changed docker-compose file to:



version: '3.5'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
expose:
- "3000"
image: api-name-service
container_name: api-name-service
networks:
- api-network

networks:
api-network:
name: api-network-service


When the services is in the same network, this services can communicate with service name, like "http://api-name-service:3000".










share|improve this question
















Im using a container with api gateway in port 80, and I'm needing communicate the api gateway between another containers (all these one using dockerfile and docker-compose). How can I do these others conteiners not expose the port to localhost but communicate internally with the api gateway?



My docker-compose:



version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "3000:3000"


Solution:



Changed docker-compose file to:



version: '3.5'

services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
expose:
- "3000"
image: api-name-service
container_name: api-name-service
networks:
- api-network

networks:
api-network:
name: api-network-service


When the services is in the same network, this services can communicate with service name, like "http://api-name-service:3000".







docker docker-compose dockerfile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 0:53







Titao Yamamoto

















asked Nov 18 '18 at 1:55









Titao YamamotoTitao Yamamoto

455




455













  • I'm not quite sure what you're asking--could you try to rephrase the question?

    – duhaime
    Nov 18 '18 at 1:58











  • Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

    – Titao Yamamoto
    Nov 18 '18 at 2:05











  • Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

    – duhaime
    Nov 18 '18 at 2:14











  • @duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

    – Titao Yamamoto
    Nov 18 '18 at 2:30






  • 1





    But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

    – gasc
    Nov 18 '18 at 3:10



















  • I'm not quite sure what you're asking--could you try to rephrase the question?

    – duhaime
    Nov 18 '18 at 1:58











  • Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

    – Titao Yamamoto
    Nov 18 '18 at 2:05











  • Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

    – duhaime
    Nov 18 '18 at 2:14











  • @duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

    – Titao Yamamoto
    Nov 18 '18 at 2:30






  • 1





    But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

    – gasc
    Nov 18 '18 at 3:10

















I'm not quite sure what you're asking--could you try to rephrase the question?

– duhaime
Nov 18 '18 at 1:58





I'm not quite sure what you're asking--could you try to rephrase the question?

– duhaime
Nov 18 '18 at 1:58













Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

– Titao Yamamoto
Nov 18 '18 at 2:05





Hi @duhaime. I'm needing just one endpoint to connect with external access (my api gateway - port 80). The others containters, with others ports, I'm trying NOT expose this ports for dont have a external connect, but having access between api gateway and these others containers.

– Titao Yamamoto
Nov 18 '18 at 2:05













Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

– duhaime
Nov 18 '18 at 2:14





Sorry, this is still not clear to me. You have an API on some host, and want other hosts to be able to communicate with the API, but you don't want to "expose" the ports over which they're communicating? Can you define "expose"? Is this all TCP communication?

– duhaime
Nov 18 '18 at 2:14













@duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

– Titao Yamamoto
Nov 18 '18 at 2:30





@duhaime sorry about that, and thank you for help me. Imagine that, I have some containers in my localhost. Just one container receive external access. Anothers can't receive external access, but need to communicate internally with this specific container.

– Titao Yamamoto
Nov 18 '18 at 2:30




1




1





But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

– gasc
Nov 18 '18 at 3:10





But you are defining only one service, what other containers do you need to communicate to app? Where are they defined? If you declare another service next to app, they both will be able to discover each other by name.

– gasc
Nov 18 '18 at 3:10












1 Answer
1






active

oldest

votes


















1














You want to use expose instead of ports:



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



For example:



services:
app1:
expose:
- "3000"
app2:
...


assuming some API on port 3000 in app1, then app2 would be able to access http://app1:3000/api






share|improve this answer


























  • I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

    – Titao Yamamoto
    Nov 18 '18 at 3:04











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357236%2fhow-can-i-communicate-between-containers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You want to use expose instead of ports:



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



For example:



services:
app1:
expose:
- "3000"
app2:
...


assuming some API on port 3000 in app1, then app2 would be able to access http://app1:3000/api






share|improve this answer


























  • I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

    – Titao Yamamoto
    Nov 18 '18 at 3:04
















1














You want to use expose instead of ports:



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



For example:



services:
app1:
expose:
- "3000"
app2:
...


assuming some API on port 3000 in app1, then app2 would be able to access http://app1:3000/api






share|improve this answer


























  • I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

    – Titao Yamamoto
    Nov 18 '18 at 3:04














1












1








1







You want to use expose instead of ports:



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



For example:



services:
app1:
expose:
- "3000"
app2:
...


assuming some API on port 3000 in app1, then app2 would be able to access http://app1:3000/api






share|improve this answer















You want to use expose instead of ports:



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



For example:



services:
app1:
expose:
- "3000"
app2:
...


assuming some API on port 3000 in app1, then app2 would be able to access http://app1:3000/api







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 '18 at 3:08

























answered Nov 18 '18 at 2:55









JonahJonah

34716




34716













  • I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

    – Titao Yamamoto
    Nov 18 '18 at 3:04



















  • I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

    – Titao Yamamoto
    Nov 18 '18 at 3:04

















I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

– Titao Yamamoto
Nov 18 '18 at 3:04





I do this, and just show the port on docker ps -a (I don't have external access now). But how can my others services call this one?

– Titao Yamamoto
Nov 18 '18 at 3:04


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357236%2fhow-can-i-communicate-between-containers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]