How to connect to an existing docker network with docker remote API (through dockerode)

I use docker-compose to create a “park” of container inter-linked. Nothing special here, I have API/Frontend/Backend etc.. There is my docker-compose.yml :

version: "2"

services:
    api:
        build: ./deimos_api/docker
        ports:
            - "39999:80"
        volumes:
            - ./deimos_api:/root/deimos_api
    asset:
        build: ./deimos_asset/docker
        ports:
            - "8000:80"
        volumes:
            - ./deimos_asset:/root/deimos_asset
        depends_on:
            - api
        links:
            - api
    data-manager:
        build: ./deimos_data_manager/docker
        ports:
            - "3333:3333"
        volumes:
            - ./deimos_data_manager:/root/deimos_data_manager
        depends_on:
            - api
        links:
            - api
    backend:
        build: ./deimos_backend/docker
        ports:
            - "1080:80"
        volumes:
            - ./deimos_backend:/root/deimos_backend
            - /var/run/docker.sock:/var/run/docker.sock
        depends_on:
            - api
            - asset
        links:
            - api

I just learn that create a “park” like this linked container on a new network. docker network ls result :

  • Mongodb docker container with client access control
  • hbase hadoop DNS static init fails with UnknownHostException in docker while spring bean init if log file exists, but works after init
  • Docker Compose when to use image over build
  • Running Docker compose with ElasticSearch on OS X gives me error sysctl: setting key “vm.max_map_count”: Read-only file system
  • docker websphere can't get the admin console
  • Use Ansible to start Docker containers on docker-machine?
  • NETWORK ID          NAME                DRIVER
    448daa341d56        bridge              bridge              
    c7feeeb44cd0        deimos_default      bridge              
    1fc2d6132b86        none                null                
    a80e41eab3cc        host                host   
    

    An other part of the project is to generated on the fly container. But I want that new container access to the deimos_api container previously created by docker-compose.

    I’m using dockerode (wrapper of Docker Remote API) in javascript with the following code :

    docker.createContainer({
        "Image": config.dockerGameServerImageName,
        "name": config.gameServerPrefix + serverName,
        "Volumes": {"/root/deimos_server":{}}
    }, function (err, container) {
        if(err){
            console.log(err);
            reject(err);
        } else {
            container.start({
                "PortBindings": { "80/tcp": [{"HostPort": lastPortUsed+""}]},
                "Binds":[config.deimosServerVolumePath+":/root/deimos_server"],
                "Links":[config.dockerApiContainerName+":api"]
            }, function (err, data) {if(err) {
                    console.log(err);
                    reject(err);
                } else {
                    console.log("Create container " + serverName);
                    gameContainer[config.gameServerPrefix + serverName] = lastPortUsed+"";
                    resolv({
                        'serverPort':lastPortUsed,
                        'serverName':serverName
                    });
                }
            });
        }
    });
    

    But I have the following error :

    Error: HTTP code is 500 which indicates error: server error - Could not get container for deimos_api_1
    

    Any idea how to specify in dockerode how to join a specific network (here deimos_default) ?

    Thank You.

    EDIT : I’m using docker 1.10.3, docker-compose 1.6.2 and dockerode 2.2.10

  • Datadog count metric dropping with multiple containers
  • Concourse cant put docker image to local repo, not a vaild repository/tag
  • Docker cannot connect to Docker Daemon even though the daemon is running
  • insecure-registry in DOCKER_OPTS
  • Redis server does not start after install in Docker
  • Where to find the tomcat folder in the docker image
  • One Solution collect form web for “How to connect to an existing docker network with docker remote API (through dockerode)”

    I find it !

    Add following option to the dockerode start process did the tricks !

    "HostConfig": {
        "NetworkMode": "deimos_default"
    }
    

    Find the row in documentation here : https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/#create-a-container

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.