Running in Docker



  • I'm leaving this here in case anyone finds it useful!

    It took me about a day of work to figure it out, but I finally got a working Dockerfile for launching jsreport as a package in my Node.js package. This example uses PM2 to launch the process, but node <file> should work fine too.

    FROM node:8
    
    ### START Puppeteer Dependencies
    # See this link for details:
    # https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
    
    # See https://crbug.com/795759
    RUN apt-get update && apt-get install -yq libgconf-2-4
    
    # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
    # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
    # installs, work.
    RUN apt-get update && apt-get install -y wget --no-install-recommends \
        && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
        && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
        && apt-get update \
        && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
          --no-install-recommends \
        && rm -rf /var/lib/apt/lists/* \
        && apt-get purge --auto-remove -y curl \
        && rm -rf /src/*.deb
    
    # It's a good idea to use dumb-init to help prevent zombie chrome processes.
    ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
    RUN chmod +x /usr/local/bin/dumb-init
    
    # Uncomment to skip the chromium download when installing puppeteer. If you do,
    # you'll need to launch puppeteer with:
    #     browser.launch({executablePath: 'google-chrome-unstable'})
    # ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
    
    # Install puppeteer so it's available in the container.
    RUN npm i puppeteer
    
    ### END Puppeteer Dependencies ###
    
    RUN npm install pm2 -g
    
    RUN mkdir -p /app
    WORKDIR /app
    
    # Build deps separately so hopefully we won't have to rebuild them
    ADD ./jsreport/package.json ./packages/package.json
    ADD ./jsreport/yarn.lock ./packages/yarn.lock
    RUN cd packages && yarn
    
    ADD jsreport ./jsreport
    RUN cp -a ./packages/node_modules ./jsreport/node_modules
    
    ADD ecosystem.config.json .
    
    ### START Puppeteer Dependencies
    ENTRYPOINT ["dumb-init", "--"]
    ### END Puppeteer Dependencies ###
    
    
    ENV chrome:launchOptions:args --no-sandbox
    CMD [ "pm2-runtime", "start", "ecosystem.config.json"]
    
    

  • administrators

    thanks for the tips and for sharing your work.

    just to clarify for anyone, the steps above are useful when you want to build your own docker image, probably because you want to run jsreport and your app in same container or because you want to change some step in the docker build process.

    we deploy docker images for each release of jsreport, so if someone wants to just quickly try jsreport or maybe deploy jsreport as standalone container it is recommend to use our docker images. more information here, our docker images are useful too as a reference to build custom images



  • Hi,

    I want to create a Dockerfile for launching jsreport as a package in my Node.js package. Currently, it is throwing errors like not able to launch the chrome browser.
    Please provide a quick help. I am having jsrepot.config.json file in the project. index.js as the starting file. script to build the application is node index.js

    Thanks


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.