Need to use wkhtmltopdf in docker node:alpine image - node.js

I have image docker image node:alpine , need to use wkhtmltopdf in some part of my API services. Here is my docker file
FROM node:alpine
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json .
# For npm#5 or later, copy package-lock.json as well
# COPY package.json package-lock.json .
RUN npm install
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
remember i already have wkhtmltopdf container on my docker

You can download it from its repo on github and call the binary within your container:
RUN curl -L https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz | tar -xJ
The above downloads and extracts it in your active working directory in your docker image.

Related

Getting error saying "missing script: start" while using "docker compose up" but i have set up "start" on package.json

I was trying to containerize the node and mongo app while I encountered the error the docker file is written as in the second image.
Image of docker compose file.
Please suggest any solution
The GITHUB link of repo - https://github.com/siddharth-codes/productdb
i suggest to annotate this line:
COPY package*.json .
and the dockerfile should be like:
FROM node:alpine
WORKDIR /usr/src/app
#initializee the workdir in host system linux
COPY . .
#npm ci will install all the dependencies of the required version
RUN npm ci
#copy files from our project folder..
CMD ["npm", "start"]
#above line is ame as npm startnp
Also, i ran docker-compose up -d and it worked fine on my server.

cannot replace to directory /var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/#ampproject/remapping with file

On my Windows machine, I am attempting to build a containerized node.js application with the following Dockerfile:
# use latest version of nodejs
FROM node:lts-alpine
# install aurelia-cli to build the app & http-server to serve static contents
RUN npm i -g http-server
RUN npm i -g aurelia-cli
# set working directory to app
# henceforth all commands will run inside this folder
WORKDIR /app
# copy package.json related files first and install all required dependencies
COPY package*.json ./
RUN npm install
# copy the rest of the files and folders & install dependencies
COPY . ./
RUN npm run build
# by default http-server will serve contents on port 8080
# so we expose this port to host machine
EXPOSE 8080
CMD [ "http-server" , "dist" ]
However, docker build . fails at the line Copy . ./. with the message cannot replace to directory /var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/#ampproject/remapping with file.
What do I need to do to get my container image to build?
Add node_modules to a .dockerignore file in the same directory as your Dockerfile, as outlined here: (h/t David Maze).
Less gracefully, simply delete the project's node_modules directory then rerun docker build.

Create a nodejs image with Docker

I am following this documentation
https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
If you follow the docs this is the dockerfile you get at end of the section.
C:\Users\dynode\node-cluster>
I have the nodejs project in this directory , where should I create my dockerfile and "WORKDIR /usr/src/app" what change should be made to this so I can move forward
Put your Dockerfile at C:\Users\dynode\node-cluster\Dockerfile.
Do not change the path for the WORKDIR - that is a path inside the container.
The only relevant paths you need to worry about are the COPY ones, which will both work as-is since they are relative paths.
The Dockerfile should be created next to the node.js source code. This can be inferred from the paths being used to add the source code into the Docker image.
As you can see, COPY package*.json ./, would imply that the Dockerfile is next to the package.json file.
As for /usr/src/app, this path is not on your machine, but rather inside the container and the Dockerfile is creating this folder inside the image. So nothing to do here.

Using SemanticUI with Docker

I setted up a Docker container running an express app. Here is the dockerfile :
FROM node:latest
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
RUN npm install -g nodemon
RUN npm install --global gulp
RUN npm i gulp
# Bundle app source
COPY . /usr/src/app
EXPOSE 3000
CMD [ "nodemon", "-L", "./bin/www" ]
As you can see, it uses the nodejs image and creates an app folder in my container, itself containing my application. IThe docker container, on start runs npm install and installs my modules on the container (thanks to that i don't have this node_modules folder in my local folder) i want to integrate SemanticUI which uses gulp. I so installed gulp on my container but the files created by semantic are only present on my container. They are not on my local folder. How can i dynamically make that those files created on my container are locally present to modify.
I thought that one of docker's great jobs was to not have node_modules installed on your local app folder .. maybe i am wrong if so please correct me
You can use data volume to share files with the container and host machine.
Something like this:
docker run ... -v /path/on/host:/path/in/container ...
or if you are using docker-compose, see volume configuration reference.
...
volumes:
- /path/on/host:/path/in/container

Deploy NoneJS application with Docker

Is it possible to develop an NoneJS application on windows (or another platform e.g. Raspbian) and deploy it on Linux with Docker?
Yes, if you dockerize your nodejs application. nodejs.org explains:
You create a new directory where all the files would live.
(package.json, server.js, ...)
You create a Dockerfile (in that same folder) using FROM node:argon which is node 4.6.1 (or another version: see hub.docker.com/_/node/: latest is 7.0.0)
That is:
FROM node:argon
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
you build and run:
docker build -t <your username>/node-web-app .
docker run -p 49160:8080 -d <your username>/node-web-app

Resources