How do I use box.json with Docker compose?

I am trying to put together a dev environment using ortussolutions/commandbox and Docker compose. My setup uses server.json to specify that I want to use Adobe 2021 instead of Lucee, and box.json to install a number of packages and Testbox.

When I used this Docker compose service, with server.json and box.json in the same folder as docker-compose.yml, this worked:

 cfml:
    image: ortussolutions/commandbox:alpine
    container_name: cfml
    volumes:
      - type: bind
        source: .
        target: /app
    ports:
      - "8080:8080"
    depends_on:
      db:
        condition: service_started
    networks:
      - main
    environment:
      - cfconfig_adminPassword=*********

However, I wanted to make the bind target the folder with my application, and not the parent folder that contains docker-compose.yml. I got as far as this:

 cfml:
    image: ortussolutions/commandbox:alpine
    container_name: cfml
    volumes:
      - type: bind
        source: ${PWD}/app
        target: /app/public
      - type: bind
        source: ${PWD}/configs/server.json
        target: /app/server.json   
      - type: bind
        source: ${PWD}/configs/.cfconfig.json
        target: /app/.cfconfig.json      
    ports:
      - "8080:8080"
    depends_on:
      db:
        condition: service_started
    networks:
      - main
    environment:
      - cfconfig_adminPassword=*******
      - BOX_SERVER_CFCONFIGFILE=/app/.cfconfig.json

With "web":{ "webroot":"/app/public" } in server.json.

The problem is that I can’t get it to use my box.json file. Currently, I get an install with Adobe Coldfusion instead of Lucee (which is how I know that server.json is being read), but none of the packages that I install with box.json are installed.

Also, the datasource that I defined in .cfconfig.json is present, but the mapping that I attempted to add is missing.
When I add it in CF Administrator, it is:
Logical path: /appname Directory path: /app/public
In .cfconfig.json, I added:

     "mappings":{
         "/appname": "/app/public"
     },

I tried copying box.json into the volume, both in / and /app, and putting it in the same folder as docker-compose.yml, but it seems to be ignoring it no matter what I do with it.

Can you tell me how to get my service to use box.json and add a mapping?

From what I can see, you are mounting in the app directory from the root of your project but the folder /app on the container only has the nested folder and two files in it. Where is the box.json file located?

Is there a reason you can’t just mount app in to /app and use the BOX_INSTALL=true environment variable?

I tried adding - BOX_INSTALL=true to the environment variables and putting box.json in the root of the source folder bound to /app, and I got a Testbox install, but no packages or mappings.

I got the packages and Testbox to load using:

cfml:
    image: ortussolutions/commandbox:alpine
    container_name: cfml
    volumes:
      - type: bind
        source: ${PWD}/configs/server.json
        target: /app/server.json   
      - type: bind
        source: ${PWD}/configs/box.json
        target: /app/box.json   
      - type: bind
        source: ${PWD}/configs/.cfconfig.json
        target: /app/.cfconfig.json     
      - type: bind
        source: ${PWD}/app
        target: /app/public/appname
 
    ports:
      - "8080:8080"
    depends_on:
      db:
        condition: service_started
    networks:
      - main
    environment:
      - cfconfig_adminPassword=*******
      - BOX_SERVER_CFCONFIGFILE=/app/.cfconfig.json
      - BOX_INSTALL=true

I moved

    "scripts":{
        "onServerInstall":"cfpm install sqlserver,chart,debugger"
    },

from box.json to server.json, and left the Testbox dev dependency and Testbox install path in box.json:

{
	"devDependencies":{
		"testbox":"^4.5.0+5"
	},
	"installPaths":{
		"testbox":"public/testbox/"
	}
}

I didn’t get the mappings to work, but I was able to solve that problem by moving the app into the appname folder.