Page is always "Welcome to nginx!" - docker

I am trying to use docker to set up a simple virtual host, serving the static files.
However, after I executed docker compose up, the localhost page will always be "Welcome to nginx!". I wonder which part did I do wrong.
Here's my code:
(1) Dockerfile:
FROM node:16-alpine AS builder
WORKDIR /app
COPY package.json ./
RUN npm install
COPY ./ ./
RUN npm run build
FROM nginx
EXPOSE 80
WORKDIR /usr/share/ngnix/html
COPY --from=builder /app/build .
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]
(2) docker-compose
version: '3'
services:
deployment-production:
build:
context: .
dockerfile: Dockerfile
ports:
- '80:80'
(3) folder strucutre:
Thanks for any help!!

Related

2 docker builds into a multi-build

I have 1 dockerfile, 1 stage of the build for the node server, serving some data, and the 2nd stage is a react app. I use a docker compose file to run the dockerfile.
I am able to access the react app via port 3000, but the 2nd stage server isn't running so I can't access the data.
Any idea how to solve it?
FROM node:12.6
WORKDIR /usr/src/app
COPY package.json .
COPY . .
EXPOSE 5500 // node server
CMD ["npm","run", "server"]
FROM node:12.6
WORKDIR /usr/src/app
COPY package.json .
RUN npm i
COPY . .
EXPOSE 3000 // react app
CMD ["npm","run", "dev"]
version: "3.9"
services:
testingapp:
container_name: testingApp
build: .
volumes:
- ./src:/app/src:delegated
ports:
- "3000:3000"
I have read various docs online.
You're trying to run the front- and back-ends in the same container. A container only runs one process, though; if you need two separate processes from the same code base then you can run two separate containers off the same image, overriding the command: on one of them.
So reduce the Dockerfile to copy the code base in, and declare one process or the other as the main container command:
FROM node:12.6
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm ci
COPY ./ ./
EXPOSE 3000
CMD ["npm", "run", "server"]
Now in your Compose file, declare two separate containers. For the second, override the command: with the alternate program to run. Both can build: the same image; the second build will come entirely from the Docker layer cache and be all but free. The code is built into the image and you don't need to replace it using volumes:.
version: '3.8'
services:
express:
build: .
ports: ['5500:3000']
react:
build: .
command: npm run dev
ports: ['3000:3000']

Container uses port bindings of unknown origin

Dockerfile contains:
FROM node:16-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY public ./public
COPY src/ ./src
RUN npm run-script build
FROM caddy:2.2.0-alpine
WORKDIR /app
COPY --from=builder /app/build build
COPY Caddyfile .
EXPOSE 3000
CMD ["/docker-entrypoint.sh"]
docker-compose.yml says:
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
And after starting the container, I see some additional bindings that came from nowhere, or at least not from what I defined in configuration files:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
3eae13fc3a1b frontend_frontend "/docker-entrypoint.…" 5 minutes ago Up 5 minutes 80/tcp, 443/tcp, 2019/tcp, 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp
frontend
Where do these 80, 443 and 2019 bindings may be coming from?
Those are exposed in the caddy Dockerfile

Nuxt Docker: Exit code 0

I am building a Dockerfile for my Nuxt app. Whenever the container starts it gets exited with error code 0 immediately.
Here is my Dockerfile:
# Builder image
FROM node:16-alpine as builder
# Set up the working directory
WORKDIR /app
# Copy all files (Nuxt app) into the container
COPY ../frontend .
# Install dependencies
RUN npm install
# Build the app
RUN npm run build
# Serving image
FROM node:16-alpine
# Set up the working directory
WORKDIR /app
# Copy the built app
COPY --from=builder /app ./
# Specify the host variable
ENV HOST 0.0.0.0
# Expose the Nuxt port
ENV NUXT_PORT=3000
EXPOSE 3000
CMD ["npm", "run", "start"]
my docker-compose.yml file has:
frontend:
container_name: frontend
build:
context: .
dockerfile: ./docker/nuxt/Dockerfile
ports:
- "3000:3000"
networks:
- app-network
When I try to see the log file of the container, it only shows this.. which doesn't help me.
> frontend#1.0.0 start
> nuxt start
OK, I needed to add .dockerignore file
frontend/.nuxt/
frontend/dist/
frontend/node_modules/

Docker does not see built folders

I'm trying to build a docker which consists of two containers. One for nginx, and another for storybook (UI docs).
My prod.yml file:
version: '3.7'
services:
storybook_container:
image: app_prod_storybook:latest
build:
context: ../
target: builder
dockerfile: Dockerfile
container_name: app_prod_storybook
ports:
- "8080:8080"
storybook_nginx:
image: app_prod_storybook_nginx:latest
build:
context: ../
target: production-build
dockerfile: Dockerfile
container_name: app_prod_storybook_nginx
restart: always
ports:
- "80:80"
depends_on:
- storybook_container
And my Dockerfile:
FROM node:lts-alpine as builder
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "build-storybook"]
FROM nginx:stable-alpine as production-build
COPY nginx/nginx.conf /etc/nginx/nginx.conf
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /usr/src/app/storybook-static /usr/share/nginx/html/docs/storybook-static
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
This build only works if I first execute two commands locally:
npm i
npm run storybook build
Otherwise, the /usr/src/app/storybook-static directory does not exist. Although the assembly container fulfills and turns off. Before turning it off, I see the storybook-static directory and it contains all the necessary files.
What am I doing wrong?

docker multistage build fails on vue.js

This is my dockerFile located at vDocker/Dockerfile
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
RUN apk add --no-cache bash
COPY ./vDocker/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
I also have docker-compose located at root directory.
version: '3'
services:
web_client:
build:
context: .
dockerfile: ./vDocker/Dockerfile
container_name: web_client
restart: unless-stopped
tty: true
volumes:
- /var/www/app/ssl/certbot/conf:/etc/letsencrypt
- /var/www/app/ssl/certbot/www:/var/www/certbot
ports:
- 80:80
- 443:443
After running docker-compose build, It gives me the following error: Service 'web_client' failed to build: COPY failed: stat /var/lib/docker/overlay2/67b326c995a1ce52fb3ee2a792d84ffe9bc403aa5962755a2b89f1ab925a1242/merged/app/dist: no such file or directory
Any idea why?
You don't need to name the second stage.
How your build looks like depends on how you set it up and I don't know it. But what you can do is:
run the first stage as a separate Dockerfile
after the last RUN add RUN ls -lart -> this should print the contents of the directory and you can check if the /app/dist really exists
For the rest your code looks good.

Resources