How to access files from docker (already existing files) from task 1, on docker task2 (same group)

Hello,

I have a group which contains two tasks:

  • Task 1 NodeJS (yarn start)
    • /app/.next/static
    • /app/.next/public
  • Task 2 Nginx
    • /home/app/public
    • /home/app/puplic/_next/static

I need the files from task 1 on task 2. The files are prebuild static files. On my classic docker-compose … I’ve created two volumes and configures both to use the same.

If I try the same on my Nomad job configuration … the folders are:

  • emtpy
  • owned by root

On docker-compose, it looks like this

  • The NodeJS
        "Mounts": [
            {
                "Type": "volume",
                "Name": "admin_portal_admin_portal_next_data",
                "Source": "/var/lib/docker/volumes/admin_portal_admin_portal_next_data/_data",
                "Destination": "/app/.next/static",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "admin_portal_admin_portal_public_data",
                "Source": "/var/lib/docker/volumes/admin_portal_admin_portal_public_data/_data",
                "Destination": "/app/public",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            },
  • The Nginx
        "Mounts": [
            {
                "Type": "volume",
                "Name": "admin_portal_admin_portal_next_data",
                "Source": "/var/lib/docker/volumes/admin_portal_admin_portal_next_data/_data",
                "Destination": "/app/public/_next/static",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "admin_portal_admin_portal_public_data",
                "Source": "/var/lib/docker/volumes/admin_portal_admin_portal_public_data/_data",
                "Destination": "/app/public",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            },

Is there any way, to solve it also with Nomad ?

cu denny

Hi,

I’ve solved it in a bit complicated way:

I added a simple docker-entrypoint:

#!/bin/sh
set -e
echo "Copy static files to share with Nginx"
test -d /app/shared || mkdir -p /app/shared/static && mkdir -p /app/shared/public
sudo /bin/chown nextjs /app/shared/public
sudo /bin/chown nextjs /app/shared/static
cp -r /app/public/* /app/shared/public/
cp -r /app/.next/static/* /app/shared/static/

exec "$@"

Which does fix the owner for the volume mountpoint, as our containers do not work as user root, but as normal user. Otherwise we can’t copy the files.
Then we copy our static files to the desired folder (which is the $ALLOC_DIR...) and finaly … the default CMD starts.
I use sudo without “-R” … just to make sure, not breaking other things.

To have sudo … we added:

....
FROM node:14.17.0-alpine AS runner
WORKDIR /app
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -g nodejs -u 1001
RUN apk add sudo ; printf 'nextjs ALL=NOPASSWD: /bin/chown nextjs /app/shared/static\nnextjs ALL=NOPASSWD: /bin/chown nextjs /app/shared/public\n' > /etc/sudoers.d/01_app
....

So … it works now. Nginx has access to the files :slight_smile:

cu denny