Kubernetes pod fails to deploy; docker image is missing/misplacing a file?

6/30/2018

I'm trying to learn my way around Kubernetes with Google Cloud Platform. I have a small Vue-based application working locally with the following Dockerfile and docker-compose.yml.

Building and bringing up this project locally works great. However, when using kompose up to create a deployment/svc/etc. for this thing, the container fails to build properly. Ultimately it ends up in a crashing loop.

Inspecting the logs shows that the issue is that npm cannot find /opt/eyeball/package.json or /opt/eyeball/package-lock.json. I'm confused since this isn't an issue when I build and push the image that my cluster is ultimately pulling down - those files are right where you'd expect them to be based on my Dockerfile. Any idea why this might be happening?

Dockerfile

FROM node:8-alpine
RUN apk --no-cache --update add gzip
RUN mkdir -p /opt/eyeball
ADD ./package.json /opt/eyeball
ADD ./package-lock.json /opt/eyeball
WORKDIR /opt/eyeball
RUN npm install
ADD . /opt/eyeball

docker-compose.yml

version: '3'

networks:
  default:
    external:
      name: overmind

services:
  eyeball:
    image: registry.gitlab.com/souldeux/eyeball:latest
    environment:
      - HOST=0.0.0.0
    ports:
      - "8080:8080"
    volumes:
      - ./:/opt/eyeball
    entrypoint: "npm run dev"
-- souldeux
docker
google-kubernetes-engine
kubernetes
npm

1 Answer

7/1/2018

You need to delete the volumes: block in your docker-compose.yml file.

The volumes: block in your docker-compose.yml directs Docker to take the contents of your local directory and mount them into the container, which hides everything that you add in the Dockerfile. When you deploy this with Kompose, this gets translated to Kubernetes directives, but since the Kubernetes environment doesn't have your local development environment, this results in the deployed containers failing.

-- David Maze
Source: StackOverflow