
docker build/push/remove for Nodejs
yarn add -D @acrool/node-docker-cli
$ cp ./node_modules/@acrool/node-docker-cli/config/nginx ./deploy/nginx
in your package.json
{
"dockerRegistry": "docker.io/imagine10255",
"scripts": {
"docker:build": "acrool-node-docker-cli build --dockerfile=./node_modules/@acrool/node-docker-cli/config/dockerfile/react/Dockerfile",
"docker:push": "acrool-node-docker-cli push"
}
}
imagine10255 is your dockerhub account, your can change your dockerhub account
# react
$ cp ./node_modules/@acrool/node-docker-cli/config/dockerfile/react/Dockerfile ./
# nest
$ cp ./node_modules/@acrool/node-docker-cli/config/dockerfile/nest/Dockerfile ./
package.json
{
"scripts": {
"docker:build": "acrool-node-docker-cli build --dockerfile=./Dockerfile"
}
}
package.json
{
"dockerRegistry": "myDockerProvider.bear.com:8443"
}
package.json
{
"scripts": {
"docker:build": "acrool-node-docker-cli build --publicUrl=/recommend --dockerfile=./Dockerfile"
}
}
In some old projects, npm build gets stuck when run inside Docker. In such cases, you can build locally and then only put the build path into the Docker image.
Dockerfile
# And then copy over node_modules, etc from that stage to the smaller base image
FROM nginx:1.19-alpine
COPY build /usr/share/nginx/html
COPY deploy/config-nginx/nginx.conf /etc/nginx/conf.d/default.conf
WORKDIR /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Be aware that
.dockerignore
should not include the build folder (the default forcreate-react-app
is 'build', while forVite
it's 'dist').
package.json
{
"scripts": {
"build": "react-scripts build",
"docker:build": "yarn build && acrool-node-docker-cli build --publicUrl=/recommend --dockerfile=./Dockerfile"
}
}
ts-node lib/build-docker/node-run.ts