- Published on
Dockerfile
- Authors
- Name
- PatharaNor
Development
Remote with SSH key
To see the big picture, I assume scenario below :
I need to download some package/library from Bitbucket via SSH key on local machine. I save the private key in ~/.ssh
name bitbucket
:
# Example the private key
cat ~/.ssh/bitbucket
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QQAAAAt..............................................zi5dh1NVGj2Wn1tSg
AAAEDFwTiDYKRKzLJTQUmMx921wPucyEtkjxRlsZOXQSHbKhKH8dIhJO/RGYJqsMrxj7/c
3HhPOLl2HU1UaPZafW1KAAAAFXBhdGhhcmEubm9AYmRtcy5jby50aA==
-----END OPENSSH PRIVATE KEY-----
For my service (or myservice
) using prisma
to initial table in PostgreSQL database. I have 4-files below in the root of the project :
Dockerfile.local
docker-compose.local.yml
entrypoint.local.sh
run.local.sh
FROM node:18-alpine
# # Use the node user from the image (instead of the root user)
# USER node
# Create app directory
WORKDIR /var/www/nest/myservice
# For using openssh access to private repo/libs
ARG SSH_PRV_KEY
RUN apk add -qU openssh git
RUN mkdir /root/.ssh && \
chmod 0700 /root/.ssh && \
ssh-keyscan -t rsa bitbucket.org >> /root/.ssh/known_hosts && \
echo "$SSH_PRV_KEY" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa
COPY package*.json ./
# Install app dependencies using the `npm ci` command instead of `npm install`
RUN yarn cache clean && yarn
COPY . .
# Generate Prisma database client code
RUN npx prisma generate --schema prisma/schema.prisma
version: '3.6'
services:
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: systemuser
ports:
- '5432:5432'
volumes:
- ./pgdata:/var/lib/postgresql/data
sysusr:
platform: linux/amd64
container_name: myservice
build:
context: ./
dockerfile: Dockerfile.local
args:
SSH_PRV_KEY: ${SSH_PRV_KEY}
ports:
- 3200:3000
env_file:
- .env.local
entrypoint:
- sh
- -c
- 'sh entrypoint.local.sh'
volumes:
- ./:/var/www/nest/myservice
- /var/www/nest/myservice/node_modules
depends_on:
- postgres
restart: always
networks:
default:
driver: bridge
#!/bin/sh
# for initialize the container
yarn migration:dev:up && \
yarn start:dev
#!/bin/sh
docker-compose -f docker-compose.local.yml down -v
if [ -z $1 ] ; then
echo "No arguments supplied"
else
mkdir -p pgdata && \
export SSH_PRV_KEY=$(cat ~/.ssh/$1) && \
docker-compose -f docker-compose.local.yml up --build
fi
Then just run :
sh run.local.sh
Enjoy!!!
Hot reload
// ...
# ...
Using Air to live reload for Go apps.
# syntax=docker/dockerfile:1
# Build
FROM golang:1.18-buster AS build
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download && \
go install github.com/cosmtrek/air@latest
COPY *.go ./
RUN chmod +x /app
EXPOSE 8080
ENTRYPOINT [ "air" ]