I am trying to create the docker image of my strapi project with cloud hosted mongodb atlas database. Below is my dockerfile code
FROM strapi/base
COPY ./ ./
RUN npm install
RUN npm run build
RUN npm run start:develop
CMD ["npm","start"]
I am running the below code to build the docker file
docker build .
I am not receiving any error but the problem is building of image is not completing, it sticks at http://localhost:1337. How can I resolve this? I have attached the screenshot . TIA :)
Your RUN npm run start:develop step is never ending since it is running the server.
You can either write that step in your CMD and remove your existing CMD ["npm","start"], or you can simply remove that step. It depends on your case.
Try the following Dockerfile:
FROM strapi/base
COPY ./ ./
RUN npm install
RUN npm run build
CMD ["npm","start"]
or
FROM strapi/base
COPY ./ ./
RUN npm install
RUN npm run build
CMD ["npm"," run", "start:develop]
Related
I am unable to build the Docker images and receiving an authentication error when attempting to build them.
When I copy the SSH key locally and run the build, it is successful. However, when attempting to run it through the pipelines, it fails with the error below. Can someone please help me with this?
I have tried building the Docker image locally and it was successful. Please assist me in building the Docker image through the Azure pipeline.
Dockerfile:
FROM node:16.13.2 as build
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
RUN npm i -g npm#8.1.2
RUN npm cache clear --force
RUN npm install --legacy-peer-deps
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/local/app/dist/angular-app /usr/share/nginx/html
EXPOSE 80
I tried to move angular building in docker container. It successfully generates dist folder and files in it, but npm script stays running infinitely. Interesting thing is that on the host it stops using node 1.18 but has same behavior using node 1.19. I changed my docker node version to 1.18 and nothing changed.
Dockerfile contains this:
FROM node:18.12 as build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
i have a problem on docker, i use docker during the developpement of my project to see how it works. But now, when i want to rebuild with my new code, nothing append, it's litteraly the same execution.
here is my dockerFile :
### STAGE 1: Build ###
FROM node as build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
COPY . .
RUN npm install -g #angular/cli
RUN npm install
RUN ng build --prod
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/* /usr/share/nginx/html
and here is the command i use to build and run my container :
docker build -t edtmaker .
docker run --name edtmaker -d -p 8888:80 edtmaker
Ok, i receive a comment who just says to clear the cache on the browser, and this worked
I have a Dockerfile and when I run it locally, everything works fine, however my build through GitHub actions seems to fail, the error I am getting is:
error An unexpected error occurred: "ENOENT: no such file or directory, stat '/home/runner/work/akira/akira/README.md'".
I tried to remove the yarn.lock but without success, a full log of the build that fails can be found here, my Dockerfile is below:
Dockerfile:
FROM node:14.0.0 AS base
WORKDIR /usr/src/app
FROM base as builder
COPY ./lerna.json .
COPY ./package.json .
COPY ./tsconfig.json .
COPY ./yarn.lock .
COPY ./packages/akira/prisma ./packages/akira/prisma
COPY ./packages/akira/src ./packages/akira/src
COPY ./packages/akira/types ./packages/akira/types
COPY ./packages/akira/package*.json ./packages/akira/
COPY ./packages/akira/tsconfig.json ./packages/akira
RUN yarn install --frozen-lockfile
RUN yarn build
FROM builder as migrate
RUN yarn workspace akira prisma migrate up --experimental
FROM base AS app
COPY --from=builder /usr/src/app/yarn.lock .
COPY --from=builder /usr/src/app/packages/akira/dist ./dist
COPY --from=builder /usr/src/app/packages/akira/prisma ./prisma
COPY --from=builder /usr/src/app/packages/akira/package.json .
RUN yarn install --production
USER node
ENV NODE_ENV=production
EXPOSE 4000
CMD ["node", "dist/index.js"]
If you look at your GitHub Actions workflow,
or the log from the failing build that you linked, it seems to be running yarn commands outside of docker.
It looks like yarn is struggling with the README symlink, not sure why, but as it seems you want to build with docker, I would try the following:
Replace this part of the yaml
- name: Use Node.js
uses: actions/setup-node#master
with:
node-version: 14.4.0
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Build packages
run: yarn build
with something like
- name: Build docker image
run: docker build .
Edit:
As pointed out in below comment, the Dockerfile includes a side-effect of deploying database migrations.
If you don't want to run everything from the Dockerfile in the Build pipeline,
you can leverage multi-stage builds and stop at a specific stage.
I.e., move the migrations into its own stage:
FROM node:14.0.0 AS base
WORKDIR /usr/src/app
FROM base as builder
COPY ./lerna.json .
<< lines omitted >>
RUN yarn install --frozen-lockfile
RUN yarn build
FROM builder AS migr
RUN yarn workspace akira prisma migrate up --experimental
FROM base AS app
COPY --from=builder /usr/src/app/yarn.lock .
<< lines omitted >>
Then you can stop after the builder stage with
docker build --target builder .
Edit 2:
Or you could keep the build pipeline and Dockerfile as it is, and instead fix the broken symlink, i.e. revert commit 0c87fa3
I have an Angular - Flask app that I'm trying to dockerize with the following Dockerfile:
FROM node:latest as node
COPY . /APP
COPY package.json /APP/package.json
WORKDIR /APP
RUN npm install
RUN npm install -g #angular/cli#7.3.9
CMD ng build --base-href /static/
FROM python:3.6
WORKDIR /root/
COPY --from=0 /APP/ .
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["app.py"]
On building the image and running the image, console gives no errors. However, it seems to be stuck. What could be the issue here?
Is it because they are both in different directories?
Since I'm dockerizing Flask as well as Angular, how can I put both in same directory (right now one is in /APP and the other in /root)
OR should I put the two in separate containers and use a docker-compose.yml file?
In that case, how do I write the file? Actually my Flask calls my Angular and both run on same port. So I'm not sure if running in two different containers is a good idea.
I am also providing the commands that I use to build and run the image for reference:
docker image build -t prj .
docker container run --publish 5000:5000 --name prj prj
In the Angular build first stage of the Dockerfile, use RUN instead of CMD.
CMD is for running a command after the final image is built.