I'm using a Docker-compose to initialize ExpressJS + VueJS and the RestFull API
This is docker compose:
version: '3'
services:
webserver:
build: ./webserver
ports:
- "3000:3000"
container_name: boleto_webserver
networks:
- boleto
volumes:
- ./webserver:/app/webserver
- /app/webserver/node_modules
website:
build: ./website
ports:
- "8080:8080"
container_name: boleto_website
networks:
- boleto
volumes:
- ./website:/app/website
- /app/webiste/node_modules
api:
build: ./api
ports:
- "3030:3030"
container_name: boleto_api
networks:
- boleto
volumes:
- ./api:/app/api
- /app/api/node_modules
networks:
boleto:
external: true
name: boleto
In DockerFile inside Website (VueJS) I run a production build:
FROM node:12
WORKDIR /app/website
COPY package*.json ./
COPY . /app/website
RUN npm install
COPY . .
EXPOSE 8080
CMD ["npm","run","build"]
Browsing localhost:3000 here is where the webserve is being launched I have this message:
Error: ENOENT: no such file or directory, stat '/app/website/build/index.html'
Analyzing website logs:
Note that the development build is not optimized.
To create a production build, run npm run build.
If I run this applications separately, all them works well! Throwing inside a docker compose this happens! Anyone can help me?
Updating
The webserver insists on run script dev, if I remove it, it does not compile
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "nodemon app.js",
"dev": "nodemon app.js"
},
FROM node:12
WORKDIR /app/webserver
COPY package*.json ./
COPY . /app/webserver
RUN npm install && npm install nodemon
EXPOSE 3000
CMD ["npm","run","serve"]
Related
I'm dockerizing an api container and want it to be able to hot reload whenever I make change in code. I created a volume to handle it but nothing happen.
Here's my docker-compose.yml file:
version: "3.8"
services:
api:
image: xinxo-api:latest
build: ./api
ports:
- "5005:5005"
networks:
- xinxo-network
volumes:
- apibuild:/app/api/build
depends_on:
- db
- redis
env_file:
- ./api/.env
restart: always
networks:
xinxo-network:
driver: bridge
volumes:
pgdata:
cache:
staticbuild:
apibuild:
Here's my Dockerfile
FROM node:16-bullseye-slim
WORKDIR /app/api/build
COPY package*.json ./
COPY yarn.lock ./
COPY tsconfig.json ./
COPY ./prisma prisma
RUN yarn
RUN yarn prisma generate
COPY . .
EXPOSE 5005
CMD ["yarn", "start"]
I only have a screen shot of my package.json file.
I have fixed this issue already by changing 2 places:
docker-compose:
volumes:
apibuild:/app/api/build -> ./api:/app/api/build
My start script in package.json
"start": "ts-node-dev --poll --respawn --transpile-only --exit-child --no-notify --ignore-watch node_modules -r tsconfig-paths/register src/app.ts"
I have a trouble with deploying app to heroku with using Github Action and Docker, here is my main.yml:
name: Deploy
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: akhileshns/heroku-deploy#v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
can someone tell me what have I wrong here? During running deployment job I'm facing with this issue:
here is also my Dockerfile and docker-compose:
docker-compose.yml
version: '3.7'
networks:
proxy:
external: true
services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
command: ["redis-server", "--requirepass", "redisPass12345!"]
networks:
- proxy
worker:
container_name: name
build:
context: .
dockerfile: Dockerfile
depends_on:
- redis
ports:
- 8080:8080
expose:
- '8080'
env_file:
- .env
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
command: npm run dev
networks:
- proxy
dockerfile
FROM node:12.17-alpine as builder
WORKDIR /dist
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "npm", "run", "dev"]
package.json
"build": "nest build",
"dev": "node dist/main.js",
Thanks for any help!
I am building a Nest.js App using Docker-compose.
The problem is when I tried "docker-compose up prod" then it shows "Error: Cannot find module '/usr/src/app/dist/main."
Thus, I explored the files in the image of the prod, but I could find the dist folder. Also, I run dist/main and it works. However, I tried docker-compose up prod, it shows the above error.
Moreover, when I tried "docker-compose up dev." It works perfectly, making a dist folder to the host machine. The main difference between the dev and prod is the command that dev is using npm run start:dev, but prod is using npm run start:prod.
This is My DockerFile
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install rimraf
RUN npm install --only=development
COPY . .
RUN npm run build
FROM node:12.19.0-alpine3.9 as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
This is my docker-compose.yaml
services:
proxy:
image: nginx:latest # 최신 버전의 Nginx 사용
container_name: proxy # container 이름은 proxy
ports:
- '80:80' # 80번 포트를 host와 container 맵핑
networks:
- nestjs-network
volumes:
- ./proxy/nginx.conf:/etc/nginx/nginx.conf # nginx 설정 파일 volume 맵핑
restart: 'unless-stopped' # 내부에서 에러로 인해 container가 죽을 경우 restart
depends_on:
- prod
dev:
container_name: nestjs_api_dev
image: nestjs-api-dev:1.0.0
build:
context: .
target: development
dockerfile: ./Dockerfile
command: npm run start:dev #node dist/src/main #n
ports:
- 3001:3000
networks:
- nestjs-network
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
restart: unless-stopped
prod:
container_name: nestjs_api_prod
image: nestjs-api-prod:1.0.0
build:
context: .
target: production
dockerfile: ./Dockerfile
command: npm run start:prod
# ports:
# - 3000:3000
# - 9229:9229
expose:
- '3000' # 다른 컨테이너에게 3000번 포트 open
networks:
- nestjs-network
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
restart: unless-stopped
networks:
nestjs-network:```
Ok... I found the solution.
At the docker-compose.yaml, .:/usr/src/app should be removed from the volumes of the service "prod." Since the "dist" folder does not exist in the local machine, if the current local directory is mounted, then it shows Not found error. Guess I should study volume much deeper.
I'm using Docker Compose for a React/Express application.
Dockerfile for the server:
FROM node:latest
WORKDIR /app/server
COPY package.json /app/server
COPY package-lock.json /app/server
RUN npm install
COPY . /app/server
CMD [ "npm", "run", "dev" ]
Dockerfile for the client:
FROM node:latest
WORKDIR /app/client
COPY package.json /app/client
COPY package-lock.json /app/client
RUN npm install
COPY . /app/client
CMD [ "npm", "start" ]
And my docker-compose file:
version: '3'
services:
server:
build: ./server
expose:
- "3001"
ports:
- "3001:3001"
volumes:
- ./server/src/:/app/server
command: npm run dev
tty: true
client:
build: ./client
expose:
- "3000"
ports:
- "3000:3000"
volumes:
- ./client/src/:/app/client
links:
- server
command: npm run start
tty: true
After running "docker-compose up" the server crashes:
npm ERR! Missing script: "dev"
However, I DO have a "dev" script inside my package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js",
"start": "node index.js"
},
What is the problem here? The script is there. Is there something wrong with my Docker files? "npm run dev" works just fine without Docker.
Thanks!
When your docker-compose.yml file says
volumes:
- ./server/src/:/app/server
this hides everything the Dockerfile did in the /app/server directory and replaces it with the contents of that host directory. Since the only things your Dockerfile does are in the /app/server directory, you're essentially not using your Docker image at all.
I'd generally recommend removing these volumes:, along with some other unnecessary options. (You do not need to expose: ports in Compose pretty much ever; you do not need to repeat the command: from the image; links: are obsolete networking setup.) You can reduce the file to just
version: '3.8'
services:
server:
build: ./server
ports:
- "3001:3001"
client:
build: ./client
ports:
- "3000:3000"
If you do include volumes:, you need to make sure that the layout of the mounted content exactly matches what's supposed to be in the container. (Try running docker-compose run server ls with and without the volumes: line.) Here you're building the image from the ./server directory, but then mounting its src subdirectory over the whole application. It may work better to mount it only on the src subdirectory inside the container too
volumes:
- ./server/src:/app/server/src
Hmm, apparently, Docker can't find a package.json file that includes a dev script.
My first suggestion would be to ensure that package.json is in the root folder of the project, at the same folder level as the docker-compose.yml.
I am using the docker integration tool to run docker-compose to start two containers, one for node and one for mongodb.
Here is the docker-compose.yml file:
version: '2.1'
services:
mongo:
container_name: "app_mongo"
hostname: "mongo"
tty: true
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/dev/null
- MONGO_INITDB_DATABASE=***********
- MONGO_INITDB_ROOT_USERNAME=************
- MONGO_INITDB_ROOT_PASSWORD=********************
volumes:
- /data/db:/data/db
ports:
- 27017:27017
command: "mongod --smallfiles --auth"
networks:
- my-app-network
group:
container_name: "app_api1"
hostname: "api1"
build:
context: .
dockerfile: api1.dev.yml
entrypoint: ["npm", "run", "debug"]
volumes:
- ".:/home/app"
ports:
- 3000:3000
- 56745:56745
depends_on:
- "mongo"
networks:
- my-app-network
networks:
my-app-network:
driver: bridge
Here is the api1.dev.yml file:
FROM node:latest
ADD package.json /tmp/package.json
RUN cd /tmp && npm install --production && npm install -g nodemon
RUN mkdir -p /home/app && cp -a /tmp/node_modules /home/app/ && mkdir -p /home/app/dist
ADD package.json /home/app/package.json
ADD .env /home/app/.env
WORKDIR /home/app
Here is the script entry in package.json:
"scripts": {
"debug": "nodemon --inspect=56745 --require ts-node/register app/app.ts"
// "debug": "nodemon -L --inspect=56745 dist/myapp/app.js"
}
I also added a new "Attach to Node.js/Chrome" item to attach to the debugging port for node.
I run the docker-compose file followed by debugging the "Attach to Node.js/Chrome" item after node is up and listening.
When I try to hit a breakpoint in a .ts file, nothing is happening. I am seeing the endpoint is called.
What are the steps involved in debugging a typescript app from docker and what am I doing wrong?
Where can I find a good tutorial that walks through how to debug typecript for a node.js app hosted inside of a docker container?
An answer was finally provided to me. Ultimately, I had to change the debug script from "debug": "nodemon -L --inspect=56745 dist/myapp/app.js" to "nodemon -L --inspect=0.0.0.0:56745 dist/myapp/app.js".