Docker volume issue

Hi, trying to run my bot inside of a docker container on my server (exposing the workdir to the host for changes). Yes, these files are stolen from the official repos. Current bind shows no files on the host and the attached error when trying to run the container. If I run the container without any mount points then it runs fine.
# ================ #
# Base Stage #
# ================ #

FROM node:20-bullseye-slim as base

WORKDIR /usr/src/app

# ENV YARN_DISABLE_GIT_HOOKS=1
ENV CI=true
ENV LOG_LEVEL=info
ENV FORCE_COLOR=true

RUN apt-get update && \
apt-get upgrade -y --no-install-recommends && \
apt-get install -y --no-install-recommends build-essential python3 dumb-init && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove

COPY --chown=node:node yarn.lock .
COPY --chown=node:node package.json .
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node .yarn/ .yarn/

ENTRYPOINT ["dumb-init", "--"]

# ================ #
# Builder Stage #
# ================ #

FROM base as builder

# ENV NODE_ENV="development"

# COPY --chown=node:node tsconfig.base.json .
COPY --chown=node:node tsconfig.json .
# COPY --chown=node:node tsup.config.ts .
# COPY --chown=node:node prisma/ prisma/
COPY --chown=node:node src/ src/

RUN yarn install --immutable
# RUN yarn run build

# ================ #
# Runner Stage #
# ================ #

# FROM base AS runner

ENV NODE_ENV="production"
ENV NODE_OPTIONS="--enable-source-maps"

# COPY --chown=node:node src/.env src/.env
# COPY --chown=node:node --from=builder /usr/src/app/dist dist

# RUN yarn workspaces focus --all --production

# Patch .prisma with the built files
# COPY --chown=node:node --from=builder /usr/src/app/node_modules/.prisma node_modules/.prisma

RUN chown node:node /usr/src/app/

USER node

CMD [ "yarn", "run", "watch:start" ]
# ================ #
# Base Stage #
# ================ #

FROM node:20-bullseye-slim as base

WORKDIR /usr/src/app

# ENV YARN_DISABLE_GIT_HOOKS=1
ENV CI=true
ENV LOG_LEVEL=info
ENV FORCE_COLOR=true

RUN apt-get update && \
apt-get upgrade -y --no-install-recommends && \
apt-get install -y --no-install-recommends build-essential python3 dumb-init && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove

COPY --chown=node:node yarn.lock .
COPY --chown=node:node package.json .
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node .yarn/ .yarn/

ENTRYPOINT ["dumb-init", "--"]

# ================ #
# Builder Stage #
# ================ #

FROM base as builder

# ENV NODE_ENV="development"

# COPY --chown=node:node tsconfig.base.json .
COPY --chown=node:node tsconfig.json .
# COPY --chown=node:node tsup.config.ts .
# COPY --chown=node:node prisma/ prisma/
COPY --chown=node:node src/ src/

RUN yarn install --immutable
# RUN yarn run build

# ================ #
# Runner Stage #
# ================ #

# FROM base AS runner

ENV NODE_ENV="production"
ENV NODE_OPTIONS="--enable-source-maps"

# COPY --chown=node:node src/.env src/.env
# COPY --chown=node:node --from=builder /usr/src/app/dist dist

# RUN yarn workspaces focus --all --production

# Patch .prisma with the built files
# COPY --chown=node:node --from=builder /usr/src/app/node_modules/.prisma node_modules/.prisma

RUN chown node:node /usr/src/app/

USER node

CMD [ "yarn", "run", "watch:start" ]
version: '3.9'

services:
lyra:
build:
context: ../
volumes:
- .:/usr/src/app
container_name: lyra
logging:
options:
max-size: '1g'
max-file: '3'
networks:
- infi
restart: always
tty: true
image: healthcareusa/lyra:latest

networks:
infi:
version: '3.9'

services:
lyra:
build:
context: ../
volumes:
- .:/usr/src/app
container_name: lyra
logging:
options:
max-size: '1g'
max-file: '3'
networks:
- infi
restart: always
tty: true
image: healthcareusa/lyra:latest

networks:
infi:
Solution:
No but you can make the GH action that also published the new image to run that command on the server
Jump to solution
13 Replies
Favna
Favna10mo ago
Please change that network name lmfao. That's an inside joke for me and me alone. and why do you want to use a volume map like that? You're supposed to build a new docker image (in GH CI) then pull and restart on the server. You're not supposed to have the source files on the server as well, at that point you may as well just use pm2 instead of docker. 1. push code 2. trigger GH action 3. this publishes a new version of the docker image to the github container registry 4. run docker compose pull lyra && docker compule up -d --force-recreate --no-deps lyra to pull and restart the bot on the server 5. ??? 6. profit!
Songbird
Songbird10mo ago
I don't want to have to check every 5 minutes (or whatever) for updates using a separate docker container on my server trollformation there a way to listen to updates? there probably is I'll look in to it
Solution
Favna
Favna10mo ago
No but you can make the GH action that also published the new image to run that command on the server
Favna
Favna10mo ago
I created https://github.com/favware/ssh-remote-action for that purpose. Currently only use it for https://github.com/favware/graphql-pokemon but in the future more.
GitHub
GitHub - favware/ssh-remote-action: A GitHub action for executing a...
A GitHub action for executing a SSH command on a remote server - GitHub - favware/ssh-remote-action: A GitHub action for executing a SSH command on a remote server
Favna
Favna10mo ago
also you dont need to check every 5 minutes. You check when you push new code. There is no reason to check otherwise. when you've pushed new code and you want it to be released to the masses you update and restart the bot. Either don't automated it at all, or automate on every commit as mentioned above
Songbird
Songbird10mo ago
this is why I am in a server with smart people
Favna
Favna10mo ago
just 1 thing to keep in mind with ssh-remote-action, it wont have access to aliases and env vars and the like on the server that you load through .bashrc / .zshrc etc. So for the command you configure keep that in mind. also best to use absolute paths if you need to cd anything so no ~/ stuff for graphql-pokemon I have a script called control.sh at /root/workspace/control.sh so I call /root/workspace/control.sh update pokedex-v8 (update = in the switchcase of the script, pokedex-v8 is the service in docker-compose) but if you have just the 1 service just embed it as the commadn, no need to call a shell script
Songbird
Songbird10mo ago
thank you!! @Favna am i correct in assuming the example workflow yml is the only one needed for building image/deploying it? just confirming that "publish" means build/push docker image confused as to why it is "on release" when the workflow is the one triggering a release? https://github.com/favware/graphql-pokemon/actions/runs/7334424446/workflow is this the relevant workflow for what I am trying to do? and how the F*** do I push to GHCR?!?
Favna
Favna10mo ago
name: Continuous Deployment

on:
push:
branches:
- main

jobs:
publish:
name: Publish image to container registries
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
push: true
context: .
tags: ghcr.io/favware/graphql-pokemon:latest

updateOnServer:
name: Update running container on server
runs-on: ubuntu-latest
needs: publish
steps:
- name: Update container on server
uses: favware/ssh-remote-action@v1
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
username: ${{ secrets.SSH_USERNAME }}
command: ${{ secrets.SSH_COMMAND }}
silent: true
name: Continuous Deployment

on:
push:
branches:
- main

jobs:
publish:
name: Publish image to container registries
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
push: true
context: .
tags: ghcr.io/favware/graphql-pokemon:latest

updateOnServer:
name: Update running container on server
runs-on: ubuntu-latest
needs: publish
steps:
- name: Update container on server
uses: favware/ssh-remote-action@v1
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }}
username: ${{ secrets.SSH_USERNAME }}
command: ${{ secrets.SSH_COMMAND }}
silent: true
@HealthCareUSA this is broken down to the essential
Songbird
Songbird10mo ago
thank you!! what keytype does this support?
Favna
Favna10mo ago
Any your server does. It just uses ssh in the background.
Songbird
Songbird10mo ago
interesting for some reason it isn't letting me use it, yet I use the same key for SFTP figured it out unsupported format lol converted to openssh format
Want results from more Discord servers?
Add your server