docker compose connecting mongodb container with node js container
i have a sharelatex container running. This docker compose file contains a mongo and redis container.
Here is the sharelatex docker compose:
version: '2'
services:
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
networks:
- test-network
depends_on:
- mongo
- redis
privileged: true
links:
- mongo
- redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
mongo:
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
- test-network
redis:
restart: always
image: redis
container_name: redis
networks:
- test-network
expose:
- 6379
volumes:
- ./redis_data:/data
networks:
test-network:
external: true
I want to create a node application which needs mongodb, too.
How can i connect these two container?
I read about network and tried out docker network but without success.
This is my node docker compose:
version: '3.5'
services:
app:
container_name: app
restart: always
build: .
ports:
- '3001:3000'
networks:
- test-network
networks:
test-network:
driver: external
and here my index.js:
// Connect to MongoDB
mongoose
.connect(
'mongodb://mongo:27017/test2',
{ useNewUrlParser: true }
)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log("errorErrorError"));
I am open for all answers...
running mongo in an own container or create a docker network. But I dont know what is the best or the easiest.
Update 1:
First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
javascript node.js mongodb docker docker-compose
add a comment |
i have a sharelatex container running. This docker compose file contains a mongo and redis container.
Here is the sharelatex docker compose:
version: '2'
services:
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
networks:
- test-network
depends_on:
- mongo
- redis
privileged: true
links:
- mongo
- redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
mongo:
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
- test-network
redis:
restart: always
image: redis
container_name: redis
networks:
- test-network
expose:
- 6379
volumes:
- ./redis_data:/data
networks:
test-network:
external: true
I want to create a node application which needs mongodb, too.
How can i connect these two container?
I read about network and tried out docker network but without success.
This is my node docker compose:
version: '3.5'
services:
app:
container_name: app
restart: always
build: .
ports:
- '3001:3000'
networks:
- test-network
networks:
test-network:
driver: external
and here my index.js:
// Connect to MongoDB
mongoose
.connect(
'mongodb://mongo:27017/test2',
{ useNewUrlParser: true }
)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log("errorErrorError"));
I am open for all answers...
running mongo in an own container or create a docker network. But I dont know what is the best or the easiest.
Update 1:
First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
javascript node.js mongodb docker docker-compose
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42
add a comment |
i have a sharelatex container running. This docker compose file contains a mongo and redis container.
Here is the sharelatex docker compose:
version: '2'
services:
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
networks:
- test-network
depends_on:
- mongo
- redis
privileged: true
links:
- mongo
- redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
mongo:
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
- test-network
redis:
restart: always
image: redis
container_name: redis
networks:
- test-network
expose:
- 6379
volumes:
- ./redis_data:/data
networks:
test-network:
external: true
I want to create a node application which needs mongodb, too.
How can i connect these two container?
I read about network and tried out docker network but without success.
This is my node docker compose:
version: '3.5'
services:
app:
container_name: app
restart: always
build: .
ports:
- '3001:3000'
networks:
- test-network
networks:
test-network:
driver: external
and here my index.js:
// Connect to MongoDB
mongoose
.connect(
'mongodb://mongo:27017/test2',
{ useNewUrlParser: true }
)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log("errorErrorError"));
I am open for all answers...
running mongo in an own container or create a docker network. But I dont know what is the best or the easiest.
Update 1:
First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
javascript node.js mongodb docker docker-compose
i have a sharelatex container running. This docker compose file contains a mongo and redis container.
Here is the sharelatex docker compose:
version: '2'
services:
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
networks:
- test-network
depends_on:
- mongo
- redis
privileged: true
links:
- mongo
- redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
mongo:
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
- test-network
redis:
restart: always
image: redis
container_name: redis
networks:
- test-network
expose:
- 6379
volumes:
- ./redis_data:/data
networks:
test-network:
external: true
I want to create a node application which needs mongodb, too.
How can i connect these two container?
I read about network and tried out docker network but without success.
This is my node docker compose:
version: '3.5'
services:
app:
container_name: app
restart: always
build: .
ports:
- '3001:3000'
networks:
- test-network
networks:
test-network:
driver: external
and here my index.js:
// Connect to MongoDB
mongoose
.connect(
'mongodb://mongo:27017/test2',
{ useNewUrlParser: true }
)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log("errorErrorError"));
I am open for all answers...
running mongo in an own container or create a docker network. But I dont know what is the best or the easiest.
Update 1:
First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
javascript node.js mongodb docker docker-compose
javascript node.js mongodb docker docker-compose
edited Nov 24 '18 at 12:41
Tobias K
asked Nov 21 '18 at 13:40
Tobias KTobias K
19412
19412
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42
add a comment |
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42
add a comment |
3 Answers
3
active
oldest
votes
You can try something like this.
Create a docker network as follows.
docker network create <NETWORK_NAME>
In your sharelatex docker compose, you can add this network (test-network is the name of the network) like this
services:
mongo:
restart: always
image: mongo
container_name: mongo
networks:
- test-network
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
test-network:
external: true
Similarly, you can do the same (use same network name) in the docker compose file for your node application.
Once both the containers are in the same network, you can use the container name as the host name to connect to it.
Additionally, you can verify if the containers are running in the same network using the following command
docker network <NETWORK_NAME> inspect
P.S.
- You should use environment variables to pass the mongo host name and
port to your node application - You can put your node application in the same docker-compose file as
the sharelatex. But that's a whole another discussion
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
add a comment |
Ok so it seems you're specifying a custom network on both instances but you're not actually naming them. The title test-network can only be used to reference it from within that same file.
networks:
test-network:
external: true
This will effectively create a custom network but with no specified name it creates a default name of [projectname]_test-network. You're effectively creating two different networks with [projectname]_test-network which is why it is trying to create a "dockernodemongo_test-network" network.
On your node docker-compose you can try:
networks:
test-network:
external:
name: [sharelatexname]_test-network
This will effectively search for a pre-existing network with that name. Alternatively you can name the network from the first instance it is created and that should save you the trouble of trying to figure out the name.
sharelatex docker-compose:
networks:
test-network:
name: test-network
external: true
node docker-compose:
networks:
test-network:
external:
name: test-network
As for why it is not creating the node network; "driver:" you have no existing plug-in called 'external' there a few built in drivers that add a number of capabilities (e.g. multi-hosting) to your network such as bridge, overlay and macvlan. You can also download other custom plug-ins. I don't believe you need these for what you're trying to accomplish however. Also since you're only using one network, all instances of "networks:" within the services are unnecessary. They will all be a part of the only specified network. The "networks:" will be useful if you have multiple networks on the same docker-compose and wish to isolate/denominate networks for specific services within it.
add a comment |
You can try this.
version: '2'
services:
mongo: // declare first
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
redis: // declare first
restart: always
image: redis
container_name: redis
expose:
- 6379
volumes:
- ./redis_data:/data
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
depends_on:
- mongo
- redis
privileged: true
links:
- mongo:mongo // added :mongo
- redis:redis // added :redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
If you declare mongo and redis after you try linking to them, docker won't know it exists.
Source: https://docs.docker.com/compose/compose-file/#links
Do note that the official docs state that: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
.
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413361%2fdocker-compose-connecting-mongodb-container-with-node-js-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try something like this.
Create a docker network as follows.
docker network create <NETWORK_NAME>
In your sharelatex docker compose, you can add this network (test-network is the name of the network) like this
services:
mongo:
restart: always
image: mongo
container_name: mongo
networks:
- test-network
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
test-network:
external: true
Similarly, you can do the same (use same network name) in the docker compose file for your node application.
Once both the containers are in the same network, you can use the container name as the host name to connect to it.
Additionally, you can verify if the containers are running in the same network using the following command
docker network <NETWORK_NAME> inspect
P.S.
- You should use environment variables to pass the mongo host name and
port to your node application - You can put your node application in the same docker-compose file as
the sharelatex. But that's a whole another discussion
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
add a comment |
You can try something like this.
Create a docker network as follows.
docker network create <NETWORK_NAME>
In your sharelatex docker compose, you can add this network (test-network is the name of the network) like this
services:
mongo:
restart: always
image: mongo
container_name: mongo
networks:
- test-network
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
test-network:
external: true
Similarly, you can do the same (use same network name) in the docker compose file for your node application.
Once both the containers are in the same network, you can use the container name as the host name to connect to it.
Additionally, you can verify if the containers are running in the same network using the following command
docker network <NETWORK_NAME> inspect
P.S.
- You should use environment variables to pass the mongo host name and
port to your node application - You can put your node application in the same docker-compose file as
the sharelatex. But that's a whole another discussion
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
add a comment |
You can try something like this.
Create a docker network as follows.
docker network create <NETWORK_NAME>
In your sharelatex docker compose, you can add this network (test-network is the name of the network) like this
services:
mongo:
restart: always
image: mongo
container_name: mongo
networks:
- test-network
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
test-network:
external: true
Similarly, you can do the same (use same network name) in the docker compose file for your node application.
Once both the containers are in the same network, you can use the container name as the host name to connect to it.
Additionally, you can verify if the containers are running in the same network using the following command
docker network <NETWORK_NAME> inspect
P.S.
- You should use environment variables to pass the mongo host name and
port to your node application - You can put your node application in the same docker-compose file as
the sharelatex. But that's a whole another discussion
You can try something like this.
Create a docker network as follows.
docker network create <NETWORK_NAME>
In your sharelatex docker compose, you can add this network (test-network is the name of the network) like this
services:
mongo:
restart: always
image: mongo
container_name: mongo
networks:
- test-network
expose:
- 27017
volumes:
- ./mongo_data:/data/db
networks:
test-network:
external: true
Similarly, you can do the same (use same network name) in the docker compose file for your node application.
Once both the containers are in the same network, you can use the container name as the host name to connect to it.
Additionally, you can verify if the containers are running in the same network using the following command
docker network <NETWORK_NAME> inspect
P.S.
- You should use environment variables to pass the mongo host name and
port to your node application - You can put your node application in the same docker-compose file as
the sharelatex. But that's a whole another discussion
answered Nov 24 '18 at 9:55
greenPadawangreenPadawan
7161814
7161814
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
add a comment |
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
this does not work... I updated the code my question how tried it: First Problem: Sharelatex does not work anymore --> sharelatex is now in another network. My nginx reverse proxy does not find sharelatex container anymore. Second Problem is: when i want to start node docker i get this error (dont know why but it want to create a new network): Creating network "dockernodemongo_test-network" with driver "external" ERROR: plugin "external" not found
– Tobias K
Nov 24 '18 at 12:40
1
1
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
I'm assuming you are running nginx as a separate service and not in a docker container. For the first point, I think you should run the nginx as a container as well. Just add it in your sharelatex compose fle. For the second point, could you please confirm whether you created a docker network separately using the docker network create <NETWORK_NAME> command?
– greenPadawan
Nov 25 '18 at 7:52
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
Also, could you please confirm if you are running these containers on the same host or different hosts?
– greenPadawan
Nov 25 '18 at 8:38
add a comment |
Ok so it seems you're specifying a custom network on both instances but you're not actually naming them. The title test-network can only be used to reference it from within that same file.
networks:
test-network:
external: true
This will effectively create a custom network but with no specified name it creates a default name of [projectname]_test-network. You're effectively creating two different networks with [projectname]_test-network which is why it is trying to create a "dockernodemongo_test-network" network.
On your node docker-compose you can try:
networks:
test-network:
external:
name: [sharelatexname]_test-network
This will effectively search for a pre-existing network with that name. Alternatively you can name the network from the first instance it is created and that should save you the trouble of trying to figure out the name.
sharelatex docker-compose:
networks:
test-network:
name: test-network
external: true
node docker-compose:
networks:
test-network:
external:
name: test-network
As for why it is not creating the node network; "driver:" you have no existing plug-in called 'external' there a few built in drivers that add a number of capabilities (e.g. multi-hosting) to your network such as bridge, overlay and macvlan. You can also download other custom plug-ins. I don't believe you need these for what you're trying to accomplish however. Also since you're only using one network, all instances of "networks:" within the services are unnecessary. They will all be a part of the only specified network. The "networks:" will be useful if you have multiple networks on the same docker-compose and wish to isolate/denominate networks for specific services within it.
add a comment |
Ok so it seems you're specifying a custom network on both instances but you're not actually naming them. The title test-network can only be used to reference it from within that same file.
networks:
test-network:
external: true
This will effectively create a custom network but with no specified name it creates a default name of [projectname]_test-network. You're effectively creating two different networks with [projectname]_test-network which is why it is trying to create a "dockernodemongo_test-network" network.
On your node docker-compose you can try:
networks:
test-network:
external:
name: [sharelatexname]_test-network
This will effectively search for a pre-existing network with that name. Alternatively you can name the network from the first instance it is created and that should save you the trouble of trying to figure out the name.
sharelatex docker-compose:
networks:
test-network:
name: test-network
external: true
node docker-compose:
networks:
test-network:
external:
name: test-network
As for why it is not creating the node network; "driver:" you have no existing plug-in called 'external' there a few built in drivers that add a number of capabilities (e.g. multi-hosting) to your network such as bridge, overlay and macvlan. You can also download other custom plug-ins. I don't believe you need these for what you're trying to accomplish however. Also since you're only using one network, all instances of "networks:" within the services are unnecessary. They will all be a part of the only specified network. The "networks:" will be useful if you have multiple networks on the same docker-compose and wish to isolate/denominate networks for specific services within it.
add a comment |
Ok so it seems you're specifying a custom network on both instances but you're not actually naming them. The title test-network can only be used to reference it from within that same file.
networks:
test-network:
external: true
This will effectively create a custom network but with no specified name it creates a default name of [projectname]_test-network. You're effectively creating two different networks with [projectname]_test-network which is why it is trying to create a "dockernodemongo_test-network" network.
On your node docker-compose you can try:
networks:
test-network:
external:
name: [sharelatexname]_test-network
This will effectively search for a pre-existing network with that name. Alternatively you can name the network from the first instance it is created and that should save you the trouble of trying to figure out the name.
sharelatex docker-compose:
networks:
test-network:
name: test-network
external: true
node docker-compose:
networks:
test-network:
external:
name: test-network
As for why it is not creating the node network; "driver:" you have no existing plug-in called 'external' there a few built in drivers that add a number of capabilities (e.g. multi-hosting) to your network such as bridge, overlay and macvlan. You can also download other custom plug-ins. I don't believe you need these for what you're trying to accomplish however. Also since you're only using one network, all instances of "networks:" within the services are unnecessary. They will all be a part of the only specified network. The "networks:" will be useful if you have multiple networks on the same docker-compose and wish to isolate/denominate networks for specific services within it.
Ok so it seems you're specifying a custom network on both instances but you're not actually naming them. The title test-network can only be used to reference it from within that same file.
networks:
test-network:
external: true
This will effectively create a custom network but with no specified name it creates a default name of [projectname]_test-network. You're effectively creating two different networks with [projectname]_test-network which is why it is trying to create a "dockernodemongo_test-network" network.
On your node docker-compose you can try:
networks:
test-network:
external:
name: [sharelatexname]_test-network
This will effectively search for a pre-existing network with that name. Alternatively you can name the network from the first instance it is created and that should save you the trouble of trying to figure out the name.
sharelatex docker-compose:
networks:
test-network:
name: test-network
external: true
node docker-compose:
networks:
test-network:
external:
name: test-network
As for why it is not creating the node network; "driver:" you have no existing plug-in called 'external' there a few built in drivers that add a number of capabilities (e.g. multi-hosting) to your network such as bridge, overlay and macvlan. You can also download other custom plug-ins. I don't believe you need these for what you're trying to accomplish however. Also since you're only using one network, all instances of "networks:" within the services are unnecessary. They will all be a part of the only specified network. The "networks:" will be useful if you have multiple networks on the same docker-compose and wish to isolate/denominate networks for specific services within it.
edited Nov 29 '18 at 20:57
answered Nov 29 '18 at 20:40
swaguar.hageswaguar.hage
112
112
add a comment |
add a comment |
You can try this.
version: '2'
services:
mongo: // declare first
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
redis: // declare first
restart: always
image: redis
container_name: redis
expose:
- 6379
volumes:
- ./redis_data:/data
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
depends_on:
- mongo
- redis
privileged: true
links:
- mongo:mongo // added :mongo
- redis:redis // added :redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
If you declare mongo and redis after you try linking to them, docker won't know it exists.
Source: https://docs.docker.com/compose/compose-file/#links
Do note that the official docs state that: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
.
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
add a comment |
You can try this.
version: '2'
services:
mongo: // declare first
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
redis: // declare first
restart: always
image: redis
container_name: redis
expose:
- 6379
volumes:
- ./redis_data:/data
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
depends_on:
- mongo
- redis
privileged: true
links:
- mongo:mongo // added :mongo
- redis:redis // added :redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
If you declare mongo and redis after you try linking to them, docker won't know it exists.
Source: https://docs.docker.com/compose/compose-file/#links
Do note that the official docs state that: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
.
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
add a comment |
You can try this.
version: '2'
services:
mongo: // declare first
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
redis: // declare first
restart: always
image: redis
container_name: redis
expose:
- 6379
volumes:
- ./redis_data:/data
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
depends_on:
- mongo
- redis
privileged: true
links:
- mongo:mongo // added :mongo
- redis:redis // added :redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
If you declare mongo and redis after you try linking to them, docker won't know it exists.
Source: https://docs.docker.com/compose/compose-file/#links
Do note that the official docs state that: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
.
You can try this.
version: '2'
services:
mongo: // declare first
restart: always
image: mongo
container_name: mongo
expose:
- 27017
volumes:
- ./mongo_data:/data/db
redis: // declare first
restart: always
image: redis
container_name: redis
expose:
- 6379
volumes:
- ./redis_data:/data
sharelatex:
restart: always
image: rigon/sharelatex-full
#image: sharelatex/sharelatex
container_name: sharelatex
depends_on:
- mongo
- redis
privileged: true
links:
- mongo:mongo // added :mongo
- redis:redis // added :redis
volumes:
- ./sharelatex_data:/var/lib/sharelatex
- /var/run/docker.sock:/var/run/docker.sock
environment:
SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
SHARELATEX_REDIS_HOST: redis
SHARELATEX_APP_NAME: ShareLaTeX
SHARELATEX_SITE_URL: https://latex.tkwant.de
If you declare mongo and redis after you try linking to them, docker won't know it exists.
Source: https://docs.docker.com/compose/compose-file/#links
Do note that the official docs state that: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
.
answered Nov 21 '18 at 14:44
Teun van der WijstTeun van der Wijst
570315
570315
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
add a comment |
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i think you dont understand my problem... Sharelatex mongo and redis works fine. Problem is i dont know how to connect mongo to node
– Tobias K
Nov 21 '18 at 16:12
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
i need a link in my node docker container to running mongo container
– Tobias K
Nov 21 '18 at 16:14
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413361%2fdocker-compose-connecting-mongodb-container-with-node-js-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Could you show your attempt to use docker network? Also, what do you mean by it didn't work?
– greenPadawan
Nov 24 '18 at 9:42
i updated it. under the first answer you can read what does not work
– Tobias K
Nov 24 '18 at 12:42