Docker Community Forums

Share and learn in the Docker community.

How to run docker container from within a docker container


I’m experimenting with running a docker container from within another container using the dockerode npm package. Does anyone have guidance on how to do this?

I am getting an error:

Error: getaddrinfo ENOTFOUND docker
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'docker'

If i execute my index.js file it runs perfectly fine, but when i try to turn the node js app executing the index.js method into a container then it gives the above error. This is my index.js file:

const Docker = require('dockerode')
const streams = require('memory-streams')

const docker = new Docker()


// you may specify a timeout (in ms) for all operations, allowing to make sure you don't fall into limbo if something happens in docker
// var docker = new Docker({host: '', port: 2375, timeout: 100});

const stdout = new streams.WritableStream()
const stderr = new streams.WritableStream()

const imageName = "sandboxrunner";

console.log("Sandbox container starting...");
console.log(`Running image: ${imageName}`);

const runDocker = () => new Promise((resolve, reject) => {
      [stdout, stderr], {
        Tty: false,
        HostConfig: {
          AutoRemove: true,
          Binds: [

    .then(([res, container]) => {
      console.log('stderr: %j', stderr.toString())
    }).then(function () {
    .catch((error) => console.log(error))

runDocker().then(function () {

and this is my docker file to build the app running the index.js file:

FROM docker
WORKDIR '/app'
COPY ./package.json ./
RUN apk add npm
RUN npm install 
COPY . .
CMD ["npm","run","start"]