Git clone private repo in docker

Git clone private repo in docker

A simple how to guide to use git clone of a private repository inside docker container. With vuejs / nodejs app.

The package.json build script

  "build": "vue-cli-service build --port 8003", # for vuejs projects
  "start:prod": "babel-node ./src/index.js", # for nodejs projects with babel-node

env file


Vuejs app

# Choose and name our temporary image.
FROM alpine as intermediate

# Take an SSH key as a build argument.

# Install dependencies required to git clone.
RUN apk update && \
    apk add --update git && \
    apk add --update openssh

# 1. Create the SSH directory.
RUN mkdir -p /root/.ssh/
# 2. Populate the private key file.
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa
# 3. Set the required permissions.
RUN chmod -R 600 /root/.ssh/
# 4. Add github to our list of known hosts for ssh.
RUN ssh-keyscan -t rsa >> ~/.ssh/known_hosts

# inject a datestamp arg which is treated as an environment variable and
# will break the cache for the next RUN command

# Clone a repository
RUN git clone [email protected]:USER/REPO_NAME.git

# default branch is master/main
# if you need to change the branch uncomment the following lines
# RUN cd /REPO_NAME && \
#    git checkout YOUR_BRANCH

## Build Stage ##

# pull the Node.js Docker image
FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# create the directory inside the container
WORKDIR /usr/src/app

# copy essential files to install dependencies
COPY --from=intermediate /REPO_NAME/app/package*.json .
COPY --from=intermediate /REPO_NAME/app/babel.config.js .
COPY --from=intermediate /REPO_NAME/app/vue.config.js .

# run npm install in our local machine
RUN npm install

# copy the generated modules and all other files to the container
COPY --from=intermediate /REPO_NAME/app/src/ ./src

# build app for production with minification
RUN npm run build

# our app is running on port 8003 within the container, so need to expose it

# the command that starts our app
CMD [ "http-server", "dist", "--port","8003" ]

# if you have a nodejs project, is not needed http-server,
# you can comment the line above and uncomment the next one
# CMD ["npm", "run", "start:prod"]

Docker-compose file

version: '3.3'

      context: .
      dockerfile: app.Dockerfile
      - SSH_KEY=${SSH_KEY}
    container_name: app
    restart: always
      - postgres
      - "8003:8003"
      - my-network

    driver: bridge


Related Posts

Deal with client requests in SaaS

How to deal with client requests in Saas which are seeing only their interests, not the product interest.

The first client of LoyalXpert is not answering anymore

Trying to implement LoyalXpert app, I lost my first customer, he's not answering anymore

Experiments with Tiktok Ads

Recently tried out TikTok ads for the first time and here are some of my learnings and challenges

People don’t care about you, until they know you care about them.

People don’t care about you, until they know you care about them. The same happens in business, you need to take care of your clients.

The One Word That Can Ruin Your SaaS Business Anyone

As a SaaS founder, you probably know how important it is to have a clear and specific target market for your product.

How I got my digital certificate connected it with ANAF

How I got my digital certificate from certSIGN and connected it with ANAF

The Ultimate List of Company Directories to Boost Your Networking

Discover a wide range of company directories to boost your business's visibility and connect with potential clients.

Discover the Best Free AI Art Tools for Your Next Masterpiece

Explore a curated collection of the finest free AI art tools, designed to help you bring your artistic vision to life.

SaaS vs. Software Agency

Discover the key differences between SaaS and Software Agencies to make informed business decisions and stay ahead in the competitive market.

Top ChatGPT Prompts for Technical People and Startup Founders

Discover the ultimate list of ChatGPT prompts designed specifically for technical people and startup founders. Enhance your AI interactions and boost productivity with these powerful prompts. Revolutionize the way you work and stay ahead of the competition. Read now!