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

Tools for Analyzing Your Competition

Before knowing where your business stands, you should look at the market and your competition. You need to know what marketing tactics and strategies are working for your audience, what traffic the competition has, and how they position.

Free Online Photo Editor with Cool Effects | Edit Images Easily

Transform your images with our free online photo editor with cool effects. Add filters, adjust colors, and apply creative enhancements. Edit your photos easily and make them stand out.

How to find the size of a table in SQL?

Learn how to determine the size of a SQL table with this informative guide. Discover efficient methods for measuring table size.

MongoDB Query date by _id field

Query date by _id in mongodb. Straighforward guide to solve your issue right away.

Unleashing the Power of Free API for Scrape Reverse Geocoding

Learn how to harness the potential of reverse geocoding with our beginner's guide to scraping APIs for free. Unlock the power today.

Discover the Power of Whatsapp-web.js for Safe and Easy Automation

Automate WhatsApp with ease using Whatsapp-web.js, a NodeJS client library that connects through the official WhatsApp Web app, reducing ban risks. Perfect for user or business accounts.

Website tours js tools

Tools to create live tours for your web project using js libraries.

Unlocking SaaS Marketing Success: Essential Resources to Learn and Grow

Discover a comprehensive collection of valuable resources to master the art of SaaS marketing.

Where to launch your startup

Do you wanna launch grandiosely your startup? Get a list of platforms where people can discover your project and can push your project directly to the sky.

Email campaign improving my SaaS convertion - Manager Flota

Users subscribe to your SaaS, but don't let the money on your table. Here's how I do it!