title: Using git submodule during Docker build
body: <p>I am building an app that has a couple different services. I am using docker and docker-compose to build all of the services. However there is some code I need to share between the services, specifically the ORM code. My issue is that when I try to call <code>git submodule update --init</code> I get the following error:</p>
  
  <pre><code>Step 6/8 : RUN git submodule update --init
   ---&gt; Running in 88e2dcfa5b36
  fatal: Not a git repository: ../.git/modules/my-repo
  ERROR: Service 'my-repo' failed to build: The command '/bin/sh -c git submodule update --init' returned a non-zero code: 128
  </code></pre>
  
  <p>I'm not sure why it's looking in <code>../</code> for the <code>.git</code> directory. I'm pretty sure I set the <code>WORKDIR</code> correctly. Here is my whole <code>Dockerfile</code></p>
  
  <pre><code>FROM node
  WORKDIR /usr/src/my-repo
  COPY package*.json ./
  RUN npm install
  COPY . .
  RUN git submodule update --init
  RUN git submodule foreach npm install
  CMD ["npm", "start"]
  </code></pre>
  
  <p>Also as a side note - the submodule is a private repository how would I clone it using SSH? Do I have to set up docker with my ssh key or something? Thanks.</p>
  
  <p>Edit: Also each of the services is a submodule of the parent project. I think that may be why git is looking in <code>../git/modules/my-repo</code> but I'm not really sure how to get around this. My directory structure is like so:</p>
  
  <pre><code>parent-repo
  --service-1
  ----orm
  --service-2
  ----orm
  </code></pre>