How to do custom docker image that has certain features disabled

I've added that to my Dockerfile, so what I have now is:

FROM docker.elastic.co/kibana/kibana:6.2.4

ENV XPACK_GRAPH_ENABLED='false'
ENV XPACK_ML_ENABLED='false'
ENV XPACK_MONITORING_ENABLED='true'
ENV XPACK_REPORTING_ENABLED='false'
ENV XPACK_SECURITY_ENABLED='false'
ENV XPACK_WATCHER_ENABLED='false'

COPY canvas-extras*.zip .

RUN ./bin/kibana-plugin install https://download.elastic.co/kibana/canvas/kibana-canvas-0.1.1949.zip

RUN ./bin/kibana-plugin install file://${PWD}/$(ls canvas-extras*.zip)

USER kibana

CMD ["/usr/local/bin/kibana-docker"]

The image took some time to optimize when installing the plugins one by one. Right after it logged that the pointer was on CMD ["/usr/local/bin/kibana-docker"], the build exited successfully immediately, so I had some suspicions:

% docker build -t tsullivan/kibana-canvas-xpack-lite:6.2.4 .
Sending build context to Docker daemon   9.06MB
Step 1/12 : FROM docker.elastic.co/kibana/kibana:6.2.4
 ---> 327c6538ba4c
Step 2/12 : ENV XPACK_GRAPH_ENABLED='false'
 ---> Using cache
 ---> e6f60ba83ce4
Step 3/12 : ENV XPACK_ML_ENABLED='false'
 ---> Using cache
 ---> d1e1a76591bd
Step 4/12 : ENV XPACK_MONITORING_ENABLED='true'
 ---> Using cache
 ---> 363f7ab99e34
Step 5/12 : ENV XPACK_REPORTING_ENABLED='false'
 ---> Using cache
 ---> 1e99787271bc
Step 6/12 : ENV XPACK_SECURITY_ENABLED='false'
 ---> Using cache
 ---> 7972f146262e
Step 7/12 : ENV XPACK_WATCHER_ENABLED='false'
 ---> Using cache
 ---> a733c1e0e64e
Step 8/12 : COPY canvas-extras*.zip .
 ---> 7f0bd1617663
Step 9/12 : RUN ./bin/kibana-plugin install https://download.elastic.co/kibana/canvas/kibana-canvas-0.1.1949.zip
 ---> Running in a2e6c619c788
Attempting to transfer from https://download.elastic.co/kibana/canvas/kibana-canvas-0.1.1949.zip
Transferring 13108504 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete
Removing intermediate container a2e6c619c788
 ---> ca994e35c0da
Step 10/12 : RUN ./bin/kibana-plugin install file://${PWD}/$(ls canvas-extras*.zip)
 ---> Running in 04bd941ddb9a
Attempting to transfer from file:///usr/share/kibana/canvas-extras-0.4.0.zip
Transferring 9050519 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete
Removing intermediate container 04bd941ddb9a
 ---> 76e920ce245e
Step 11/12 : USER kibana
 ---> Running in 57978384ca8c
Removing intermediate container 57978384ca8c
 ---> 1762eb6672db
Step 12/12 : CMD ["/usr/local/bin/kibana-docker"]
 ---> Running in ba8b29e11860
Removing intermediate container ba8b29e11860
 ---> 6fd7e0a33fcb
Successfully built 6fd7e0a33fcb
Successfully tagged tsullivan/kibana-canvas-xpack-lite:6.2.4

I brought up containers in the compose file, then looked at what Kibana was doing:

~/elastic/elastic-stack-docker(add-canvas-extras↑4|✔) % docker-compose up -d
Creating network "elastic-stack-docker_default" with the default driver
Creating my-es1               ... done
Creating my-es-proxy          ... done
Creating my-logstash-avocados ... done
Creating my-kibana            ... done
Creating my-apm1              ... done
Creating my-chatbot           ... done
Creating my-web               ... done
~/elastic/elastic-stack-docker(add-canvas-extras↑4|✔) % docker-compose logs -f kibana
Attaching to my-kibana
my-kibana        | {"type":"log","@timestamp":"2018-05-16T16:50:03Z","tags":["info","optimize"],"pid":1,"message":"Optimizing and caching bundles for stateSessionStorageRedirect, status_page, timelion, canvas, monitoring, dashboardViewer, apm and kibana. This may take a few minutes"}

So adding the CMD didn't seem to result in an image that is built with optimization done. 🤷

Looks like this issue is what this feature request is about: https://github.com/elastic/kibana/issues/6057, that seems like it would be a really helpful addition.