Best Practice to Use Multiple Containers with docker-compose



I am using CircleCI 2.0 and I am planning to use specific version of Node.js on my CircleCI.

I have to use docker-compose to work with multiple docker containers, but according to these two CircleCI guides Running Docker Commands and Installing and Using docker-compose, I wonder if my docker containers can communicate/interact with each other as they did before with machine mode.

So I want to get either the way to allow containers to communicate with each other without problem with docker mode or the way to upgrade Node.js with machine mode.

Thank you in advance.

  • PS: Running Docker Commands
    The job and remote docker run in separate environments. Therefore, Docker containers cannot directly communicate with the containers running in remote docker.

  • PS: Installing and Using docker-compose
    If you want to use docker compose to manage a multi-container setup, use the machine key in your config.yml file and use docker-compose as you would normally.

Unable to use Docker with circleci/node image

You haven’t said explicitly, but I take it that you are wanting to move to the docker executor?

Maybe. How do these communicate presently - HTTP/S? Sockets? Shared volumes?


_wondering if containers can communicate/interact with each other as they did before with machine mode means : _
With machine mode/key, I could use docker-compose to run multiple containers. I was able to access to db container with localhost and share a local directory with a container. But now with docker mode, I can’t.

That’s why I am wondering and here is another text from Installing and Using docker-compose:
For example, use of volumes is restricted. If you have a docker-compose file that shares local directories with a container, it is possible to do this with the machine key, but not with docker. Even though using docker combined with setup_remote_docker provides a remote engine similar to the one created with docker-machine, volume mounting and port forwarding do not work as expected in this setup.


Related: Docker in docker not mounting volumes

So, the problem is that with the Docker executor, your containers may be split over several nodes, so there is no “localhost”. There is on Machine - so, the first question is, do you have a need to switch? What’s the problem with Machine, except it being a bit slower to boot up?


If I am able to run specific version of Node.js with Machine, it will be the best choice for me!


Fair enough. You could also try running your tests inside a Docker Compose container, so you can set up the version of Node you want without worrying whether Machine supports it.


I also tried to upgrade Node with Machine in the following, but version keeps pristine (v6.1).
Another problem with this approach is that I can only install the latest version of v8 but not a specific/exact version. And it seems that the machine should be restarted before newly installed nodejs can run ~ but didn’t know how. Could you correct me?

        machine: true
            - checkout
            - run:
                name: Upgrade node.js
                command: |
                    curl -sL | sudo -E bash -
                    sudo apt-get install -y nodejs
                    node -v
            - run: npm run build:prod
            - run: docker-compose up -d
            - run: npm run test-e2e


Probably not without more detail (and note that some of this stuff really requires trial-and-error with an actual Circle machine).

I would suggest you keep trying, but make use of these notes/ideas:

  • We’d need to see a whole config file, not a partial one (for example I don’t know what machine this is based on). For getting help on the internet, cut it down to the minimum possible config (the last three lines are probably not required - you just want the machine to install/upgrade Node, report the version, and exit). Make it as easy as possible to help you.
  • Does the build output indicate that your install succeeded?
  • What makes you think the machine should be restarted?
  • It is possible that the machine installs Node is one place and your command installs it in another, but your system path prefers the first location. Consider doing the install on a non-Node image, so there is only one to choose from.


OK, thanks for your help, @halfer

I could upgrade node by preinstalled nvm on Machine.

The following references were helpful to me:


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.