0

Say I want to run a container with ganache-cli and truffle globally installed for dev purposes.

I have this first attempt Dockerfile

FROM node:15-alpine

RUN mkdir -p /home/node/app

WORKDIR /home/node/app

COPY . .

RUN apk add -t .gyp --no-cache git python g++ make &&\
    npm install -g truffle ganache-cli &&\
    npm install &&\
    apk del .gyp

ENTRYPOINT [ "/bin/sh" ]
CMD [ "./entry.sh" ]

which executes entry.sh at start:

#!/bin/bash

ganache-cli -m "test test test test test test test test test test test junk" -h 0.0.0.0 --secure &

sleep 2

truffle migrate --network develop

wait

and this works, for sure; but I want to make the process of building the image as fast as possible. Do someone knows how can I improve this Dockerfile?

UPDATE: I am installing this Docker image within a container. There is no cache between builds because a new container is created everytime. This is know as Docker-in-Docker.

3
  • have you looked at this devopsprodigy.com/blog/6-ways-to-build-docker-images-faster – Majd TL May 4 at 14:40
  • I would suggest switching the COPY and RUN command. RUN will install the packages and that layer will remain most of the time the same unless the packages are updated. The code you are copying into the container might change more often and the layer will change. – Donut May 5 at 8:16
  • I think I can help you. Give me some time. – Vignesh Karthikeyan May 11 at 7:35
0

For the docker bit, I believe the COPY and RUN commands being interchanged as Donut mentioned in the comments could help. Reference for this and backing of the claim: Semaphore Article explaining the layer caching. But Since you are using a docker in docker type build this is unlikely to be much.

For the Ethereum dev tools themselves, I believe this is as fast(as few modules packaged together) as possible from looking at the docs.

For the actual installation of tools, possibly consider using yarn install or pnpm install. Touted performance increases are in the range of 80% - 88% faster than npm install. enter image description here


Excuse this opinion-based answer community.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.