Returning value outside of function

I’m looking to use graphQL to query a docker machine api and get a list of containers for react docker admin style project. I’m using dockerode an NPM module to make the request. The first function getCOntainerById is how I would typically return some items from rethinkdb.

I can’t seem to figure out how to return the containers array in the docker.listContainers function as it’s only defined inside the scope and undefined at the end of the fetchContainers function return.

  • How to view Docker image layers on Docker Hub?
  • Docker-compose and Docker-swarm
  • Docker container automation on the cloud
  • How to override default docker container command or revert to previous container state?
  • How to share a Docker container folder when it is not empty?
  • Prevent Docker-Engine restart during apt-get upgrade
  • import Docker from 'dockerode'
    var docker = new Docker({host: 'http://127.0.0.1', port: 52376});
    
    export default {
      getContainerById: {
        type: Container,
        args: {
          id: {type: new GraphQLNonNull(GraphQLID)}
        },
        async resolve(source, {id}, {rootValue}) {
          isLoggedIn(rootValue);
          const container = await r.table('containers').get(id);
          if (!container) {
            throw errorObj({_error: 'Container not found'});
          }
          return container;
        }
      },
      fetchContainers: {
        type: new GraphQLList(Container),
        async resolve(source, {id}, {rootValue}) {
          isLoggedIn(rootValue);
          docker.listContainers(function(err, containers) {
    
          });
    
          if (!containers) {
            throw errorObj({_error: 'Container not found'});
          }
    
          return containers
        }
      }
    };
    

    Help would be greatly appreciated. Thank you.

  • Forwarding domains to docker containers
  • How to connect mysql in a rails appliation with docker?
  • Why do I get unauthorized: authentication required from a docker pull from docker hub?
  • Fail to create postgres extensions through bash script
  • X11 forwarding with PyCharm and Docker Interpreter
  • How to push to AWS EC2 Service Container from a specific git branch (ie 'staging')
  • One Solution collect form web for “Returning value outside of function”

    async resolve(source, {id}, {rootValue}) {
      isLoggedIn(rootValue);
      const containers = await new Promise((resolve, reject) => {
        docker.listContainers((err, containers) => {
          if (err) reject(err);
          resolve(containers);
        });
      })
    
      if (!containers) {
        throw errorObj({_error: 'Container not found'});
      }
    
      return containers
    }
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.