How to start webpack build from docker container?

The application I am creating is written in ES6, and other goodies are overloaded with webpack inside the Docker container. At the moment, everything works from creating an internal directory, installing dependencies, and creating a compiled package file.

When the container starts, it says that dist / bundle.js does not exist. Unless I create a package file in the host directory, it will work.

I tried to create a volume for the dist directory in it, it works for the first time, but after making changes and rebuilding it does not pick up new changes.

What I'm trying to achieve is to create a container and run the compiled package. I'm not sure if part of the web package should be in the Docker file as a build step or at runtime, as CMD ["yarn", "start"] , but RUN ["yarn", "start"] works.

Any suggestions and help help. Thanks in advance.

 |_src |_index.js |_dist |_bundle.js |_Dockerfile |_.dockerignore |_docker-compose.yml |_webpack.config.js |_package.json |_yarn.lock 

Docker-compose.yml

 version: "3.3" services: server: build: . image: selina-server volumes: - ./:/usr/app/selina-server - /usr/app/selina-server/node_modules # - /usr/app/selina-server/dist ports: - 3000:3000 

Dockerfile

 FROM node:latest LABEL version="1.0" LABEL description="This is the Selina server Docker image." LABEL maintainer="AJ alvaroo@selina.com " WORKDIR "/tmp" COPY ["package.json", "yarn.lock*", "./"] RUN ["yarn"] WORKDIR "/usr/app/selina-server" RUN ["ln", "-s", "/tmp/node_modules"] COPY [".", "./"] RUN ["yarn", "run", "build"] EXPOSE 3000 CMD ["yarn", "start"] 

.dockerignore

 .git .gitignore node_modules npm-debug.log dist 

package.json

 { "scripts": { "build": "webpack", "start": "node dist/bundle.js" } } 
+5
source share

Source: https://habr.com/ru/post/1270510/


All Articles