I created a GKE cluster and inside it I created single pod with 2 conatiners with this yaml settings.

apiVersion: v1
kind: Pod
  name: django-nginx

  restartPolicy: Never

  - name: universal
    emptyDir: {}


  - name: nginx
    image: nginx
    - name: universal
      mountPath: /app_api

  - name: django
    image: django
    - name: universal
      mountPath: /app_api

and I'm imposting app code while building image with Dockerfile, part of which is here

FROM nginx
COPY ./app_api /app_api

but when I connect to container and ls into this directory, it shows no data. I want that code to be copied to that volume. how will it be done??


/app_api directory is empty in both containers because you mounted emptyDir over it (it's called "empty" for reason).

You have two ways to "share" files between containers:

  • Add files to both images (nginx and django) on build stage and do not use volume in pod. Technically you will have 2 different copy of data, so changes in one container will not be applied to another.
  • Add init container that will copy content from image to emptyDir volume on pod start up. Something like this (note that it will not copy "dot files" from root of /app_api/):
    - name: init
      image: nginx
      command: ["cp" "-pr" "/app_api/*" "/universal/"]
      - name: universal
        mountPath: /universal
  • Ty @seleznev, 1 more related query tho, I want these containers to talk to eachother, keeping in view that nginx container forwards request to django, and a services for nginx is exposed. Can I do it with single yaml file? And how would it be accomplished? – Sollosa Jun 19 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.