My structure is as the following
- Code
- package.json
- all the other directories and files of my project
- Dockerfile
- .gitlab-ci.yml
- Read Me
when I'm trying to create a docker image using Dockerfile the image doesn't work because it always says that Code folder does not exist - it doesn't show the error in the implementation but shows the error when I run the image.
Here is my dockerfile
FROM node:18.1.0-buster-slim
RUN apt-get update && apt-get -y upgrade
WORKDIR /code
EXPOSE 8443
COPY /code/package.json /code/package.json // I believe the error is here
RUN npm install
COPY /code/. /code // I believe the error is here
# Jave Config
RUN echo 'deb http://ftp.debian.org/debian stretch-backports main' | tee /etc/apt/sources.list.d/stretch-backports.list
RUN apt-get update && apt-get -y upgrade && \
apt-get install -y openjdk-11-jre-headless && \
apt-get clean;
CMD ["node","app.js"]
I have also tried to put the dockerfile inside Code folder which is more appropriate but I did not know how to reference that in gitlab-ci.yml. The only solution worked to me is when extracting all the files and folders inside Code and but them on the root folder, but this solution is not fit my current structure.
This is also my yaml config in case you would like to have a look.
stages:
- build-docker-image
docker-build:
# Use the official docker image.
image: docker:20.10.16
stage: build-docker-image
only:
- dev
tags:
- builder
services:
- name: docker:20.10.16-dind
before_script:
- something here...
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"