1. Optimize Dockerfile: By optimizing the instructions in Dockerfile, unnecessary dependencies and redundant files can be reduced. For example, you can use the RUN command to clean up cache and temporary files, and use the COPY command to copy necessary files to avoid copying unnecessary directories.
2. Use multi-stage compilation: Multi-stage compilation can generate multiple mirror stages in the construction process, and each stage only contains necessary dependencies and files. This can minimize the final image size.