I’m running into an issue where my code is not being mounted into my Docker container when using Skaffold on Windows. My setup involves a Kubernetes cluster managed by Skaffold, and I’m developing on a Windows machine.
Here’s my setup:
Skaffold Configuration (skaffold.yaml):
apiVersion: skaffold/v2beta12
kind: Config
metadata:
name: healthflow
build:
local:
push: true
artifacts:
- image: yazangali/authservice
context: authservice
docker:
dockerfile: Dockerfile # Production Dockerfile
- image: yazangali/userservice
context: userservice
docker:
dockerfile: Dockerfile # Production Dockerfile
deploy:
kubectl:
manifests:
- k8s/authservice/deployment.yaml
- k8s/authservice/service.yaml
- k8s/userservice/deployment.yaml
- k8s/userservice/service.yaml
- k8s/nginx-deployment.yaml
- k8s/nginx-service.yaml
- k8s/nginx-configmap.yaml
profiles:
- name: development
build:
artifacts:
- image: yazangali/authservice-dev
context: authservice
docker:
dockerfile: Dockerfile.dev # Use the dev Dockerfile for development
- image: yazangali/userservice-dev
context: userservice
docker:
dockerfile: Dockerfile.dev # Use the dev Dockerfile for development
deploy:
kubectl:
manifests:
- k8s/authservice/deployment-dev.yaml
- k8s/authservice/service.yaml
- k8s/userservice/deployment-dev.yaml
- k8s/userservice/service.yaml
- k8s/nginx-deployment.yaml
- k8s/nginx-service.yaml
- k8s/nginx-configmap.yaml
- name: production
build:
artifacts:
- image: yazangali/authservice
context: authservice
docker:
dockerfile: Dockerfile # Use the production Dockerfile
- image: yazangali/userservice
context: userservice
docker:
dockerfile: Dockerfile # Use the production Dockerfile
deploy:
kubectl:
manifests:
- k8s/authservice/deployment.yaml
- k8s/authservice/service.yaml
- k8s/userservice/deployment.yaml
- k8s/userservice/service.yaml
- k8s/nginx-deployment.yaml
- k8s/nginx-service.yaml
- k8s/nginx-configmap.yaml
Kubernetes Deployment for Development (deployment-dev.yaml):
apiVersion: apps/v1
kind: Deployment
metadata:
name: authservice
spec:
replicas: 1
selector:
matchLabels:
app: authservice
template:
metadata:
labels:
app: authservice
spec:
containers:
- name: authservice
image: yazangali/authservice-dev
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: "development"
volumeMounts:
- name: auth-code
mountPath: /usr/src/app
volumes:
- name: auth-code
hostPath:
path: "/mnt/c/Users/FPCC/Desktop/web-dev/healthflow/authservice"
type: DirectoryOrCreate
Dockerfile for Development (Dockerfile.dev):
FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
When I run
skaffold dev -p development
the services are created, but the src folder inside the container is empty. As a result, Nodemon cannot find the src/index.ts file and throws an ERR_MODULE_NOT_FOUND error.
I’ve ensured that Docker Desktop is set up to share the C: drive and that the paths are correctly formatted using /mnt/c/….
I believe the problem is in the way of how mounting works in kubernetes pods.
What could be causing the code not to mount properly inside the container? How can I resolve this issue so that my code is correctly mounted and Nodemon can detect changes?
I configured Skaffold to use a development profile with volume mounts to share my local code with the Docker container. I ensured the paths were correct and that Docker Desktop was set up to share my C: drive. I expected the src folder inside the container to contain my local code and for Nodemon to restart the service on code changes.
However, when I ran skaffold dev -p development, the services started, but the src folder inside the container was empty. Nodemon couldn’t find the src/index.ts file and threw an ERR_MODULE_NOT_FOUND error.