Git Product home page Git Product logo

Comments (5)

AlexZeitler avatar AlexZeitler commented on August 11, 2024

Can you please provide your Dockerfile and how you're importing docker-compose (this lib)

from docker-compose.

Steveb-p avatar Steveb-p commented on August 11, 2024

To make this work, docker-compose that is inside the container needs to talk with the "host's" docker.

See https://shisho.dev/blog/posts/docker-in-docker/

Specifically, the second part.

from docker-compose.

raz-m12 avatar raz-m12 commented on August 11, 2024

Thank you both for the replies. Here is the code I'm using:

File called server.js:

// The javascript file used to import docker-compose (this lib)
const compose = require('docker-compose');

compose.upAll({ cwd: "/opt/docker-compose-projects/hello-node", log: true }).then(
  () => {
    console.log('success');
  },
  (err) => {
    console.log('fail:', err.message);
  }
)

The Dockerfile creating the image myimage/test:v1.0:

FROM node:14-alpine

COPY ./package.json /app/package.json
COPY ./package-lock.json /app/package-lock.json
COPY ./server.js /app/server.js

WORKDIR /app

RUN npm install

VOLUME /app
VOLUME ["/opt/docker-compose-projects"]

COPY docker-compose-projects /opt/docker-compose-projects

CMD []
WORKDIR /app
ENTRYPOINT npm start --prefix /app

WORKDIR /opt/docker-compose-projects/

This is the docker-compose.yml file (creating the volume: /var/run/docker.sock:/var/run/docker.sock as @Steveb-p suggested).

version: "3.8"

services:
  docker_compose:
    image: "myimage/test:v1.0"
    container_name: docker_compose
    hostname: docker_compose
    working_dir: /opt/docker-compose-projects/
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Using the above code, I get the following error:

error: spawn docker-compose ENOENT

Locally (outside containers), the code works without errors.

from docker-compose.

Steveb-p avatar Steveb-p commented on August 11, 2024
error: spawn docker-compose ENOENT

basically means that docker-compose binary is not available. Install docker-compose inside the container, and I hope that should do it.

from docker-compose.

raz-m12 avatar raz-m12 commented on August 11, 2024

Thanks, I was able to get it working by adding this line to the Dockerfile:

COPY --from=docker/compose:latest /usr/local/bin/docker-compose /usr/bin/docker-compose

from docker-compose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.