How do I maintain a folder structure in dockerfile - dockerfile

I'm trying to move my nestjs app into container. But I met some problems. I used grpc in my project and my proto files are stored in a protos folder which is the same level as the src folder. My file structure is like this.
-project folder
--protos
---...proto files
--src
---...other codes
And in my docker file, I copied the proto folders, however, when I run the docker-compose up, it shows it cannot find my proto files. But if I just go with npm run start, it runs normally. Here is my dockerfile:
FROM node:14 AS builder
# Create app directory
WORKDIR /app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
COPY prisma ./prisma/
COPY protos ./protos/
# Install app dependencies
RUN npm install
COPY . .
RUN npm run build
FROM node:14
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/protos ./protos
EXPOSE 5273
CMD [ "npm", "run", "start:dev" ]
enter code here
Am I missing something here? Any advises will be appreciated.

Related

Docker image creation using nodejs with redis

i am using below Docker file. how can i configure redis in my Dockerfile?
also i am using build command docker build - < Dockerfile but this didn't work out.
if i run this command the following error will show
COPY failed: no source files were specified
FROM node:lts
RUN mkdir -p /app
WORKDIR /app
COPY package*.json /app
RUN yarn
COPY . /app
CMD ["yarn","run","start"]
One cannot use docker build - < Dockerfile to build an image that uses COPY instructions, because those instructions require those files to be present in the build context.
One must use docker build ., where . is the relative path to the build context.
Using docker build - < Dockerfile effectively means that the only thing in the build context is the Dockerfile. The files that one wants to copy into the docker image are not known to docker, because they are not included in the context.

AWS CodePipeline environment variables not passed to Docker

In my CodeBuild step I have an environment variable called VUE_APP_BACKEND defined as a URL. I confirmed that this part is OK by adding echo $VUE_APP_BACKEND to my buildspec.yml.
That one will output
[Container] 2020/11/26 13:22:25 Running command echo $VUE_APP_BACKEND
https://my-url-here
However when I try to forward this argument into the docker build it is lost. Am I doing it incorrectly?
I have a Dockerfile that looks like this. The echo part outputs nothing.
#build stage
FROM node:12.18.2-alpine3.10 as build-stage
ARG VUE_APP_BACKEND
ENV VUE_APP_BACKEND $VUE_APP_BACKEND
RUN echo $VUE_APP_BACKEND
# Create app directory
RUN mkdir -p /app
WORKDIR /app
# Bundle app source
COPY package*.json ./
COPY .npmrc ./
RUN npm install
COPY . .
RUN npm run build
#production stage
FROM nginx:1.14.1-alpine as production-stage
COPY --from=build-stage /app/dist/spa /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD [ "nginx", "-g", "daemon off;" ]

Google Cloud Run: COPY fails when changing source folder from ./ to build

$ gcloud builds submit --tag gcr.io/projectname/testserver
// ... works fine until the COPY step:
Step 6/7 : COPY build ./
COPY failed: stat /var/lib/docker/tmp/docker-builder653325957/build: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
That build folder listed above, /var/lib/docker/tmp/docker-builder653325957/build, is not a local folder. Does Cloud Builder create a temp folder in that format?
How do I get it to copy my local build folder?
I also tried COPY ./build ./ but the CLI output was the same
Dockerfile below.
FROM node:12-slim
# Create app folder
WORKDIR /usr/src/app
# Install app deps. Copy the lock file
COPY package*.json ./
RUN npm install
ENV SCOPES=removed \
SHOPIFY_API_KEY=removed \
SHOPIFY_API_SECRET=removed \
CLIENT_APP_URL=removed
COPY build ./
CMD ["node", "server.js"]
The gcloud command uses the .gitignore and .gcloudignore files to determine which files and directories to include with the Docker build. If your build directory is listed in either of these files, it won't be available to copy into your container image.

build and deploy from one dockerfile or have different files for each purpose?

I am creating react app and want to build and deploy the build to new container?
I am trying stages in dockerfile.
FROM node:alpine as builder
WORKDIR /app/
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
EXPOSE 80
well the steps you followed is all correct,You just missed the part from where to copy the build folder and paste it in the nginx image.
by default nginx takes files to serve from
usr/share/nginx/html
try the bellow code.
FROM node:alpine as builder
WORKDIR /app/
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
if it doesnt work do comment.

Dockerfile copying war to local linked volume

I have a note app that I am building with a Dockerfile in the maven app.
I want to copy the artifact note-1.0.war to local linked volume to folder like webapps. So far I have the following in a Dockerfile:
FROM maven:latest
MAINTAINER Sonam <emailme#gmail.com>
RUN apt-get update
WORKDIR /code
#Prepare by downloading dependencies
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
#Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "clean"]
#RUN ["mvn", "install"]
RUN ["mvn", "install", "-Dmaven.test.skip=true"]
RUN mkdir webapps
COPY note-1.0.war webapps
#COPY code/target/note-1.0.war webapps
Unfortunately, I keep seeing the "no such file or directory" at the COPY statement. The following is the error from build on Docker hub:
...
---> bd555aecadbd
Removing intermediate container 69c09945f954
Step 11 : RUN mkdir webapps
---> Running in 3d114c40caee
---> 184903fa1041
Removing intermediate container 3d114c40caee
Step 12 : COPY note-1.0.war webapps
lstat note-1.0.war: no such file or directory
How can I copy the war file to a "webapps" folder that I executed in
RUN mkdir webapps
thanks
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.
In your example the docker build is looking for note-1.0.war in the same directory than Dockerfile.
If I understand your intention, you want to copy a file inside the image that is build from previous RUN in Dockerfile.
So you should use something like
RUN cp /code/target/note-1.0.war /code/webapps