docker compose connecting mongodb container with node js container












8















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










share|improve this question

























  • 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
















8















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










share|improve this question

























  • 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














8












8








8


1






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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












3 Answers
3






active

oldest

votes


















6





+25









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.




  1. You should use environment variables to pass the mongo host name and
    port to your node application

  2. You can put your node application in the same docker-compose file as
    the sharelatex. But that's a whole another discussion






share|improve this answer
























  • 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



















1














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.






share|improve this answer

































    -1














    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.






    share|improve this answer
























    • 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













    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%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









    6





    +25









    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.




    1. You should use environment variables to pass the mongo host name and
      port to your node application

    2. You can put your node application in the same docker-compose file as
      the sharelatex. But that's a whole another discussion






    share|improve this answer
























    • 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
















    6





    +25









    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.




    1. You should use environment variables to pass the mongo host name and
      port to your node application

    2. You can put your node application in the same docker-compose file as
      the sharelatex. But that's a whole another discussion






    share|improve this answer
























    • 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














    6





    +25







    6





    +25



    6




    +25





    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.




    1. You should use environment variables to pass the mongo host name and
      port to your node application

    2. You can put your node application in the same docker-compose file as
      the sharelatex. But that's a whole another discussion






    share|improve this answer













    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.




    1. You should use environment variables to pass the mongo host name and
      port to your node application

    2. You can put your node application in the same docker-compose file as
      the sharelatex. But that's a whole another discussion







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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













    1














    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.






    share|improve this answer






























      1














      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.






      share|improve this answer




























        1












        1








        1







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 29 '18 at 20:57

























        answered Nov 29 '18 at 20:40









        swaguar.hageswaguar.hage

        112




        112























            -1














            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.






            share|improve this answer
























            • 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


















            -1














            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.






            share|improve this answer
























            • 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
















            -1












            -1








            -1







            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.






            share|improve this answer













            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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





















            • 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




















            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%2f53413361%2fdocker-compose-connecting-mongodb-container-with-node-js-container%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

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            ts Property 'filter' does not exist on type '{}'

            Notepad++ export/extract a list of installed plugins