If there are top ten buzzwords in the technology industry in the year of 2019, is sure to be one of them. With the popularity of Docker, more and more scenarios are using Docker in the front-end field. This article shows how do we use Docker in the visualization interface of , a distributed open source graph database. container Nebula Graph Why Using Docker Docker is widely used in daily front-end development. (A visualization tool for ) uses Docker based on the following considerations: Nebula Graph Studio Nebula Graph : There are several services behind our tools, such as existing services from different technology stacks, and pure front-end static resources. Unified operating environment : Currently, cloud services are under development. We want a smooth experience of the combined services, and Docker makes this possible with the ability of starting and applying all the services locally just in one step. Low user cost : This front-end project is inspired by the . Quick deployment Nebula Graph Docker Image Building Docker Image We need to build an image first before hosing our services with Docker. Here we need a configuration file named that contains descriptions of the building steps. To be brief, we need to copy the project into the image and set the startup method: Dockerfile node: # Select base image FROM 10 # Set work directory WORKDIR /nebula-web-console # Copy the current project to the /nebula-web-console directory of the image ADD . /nebula-web-console # Download front-end dependency in the image RUN npm install # Run the building RUN npm run build EXPOSE 7001 # Deployment commands executed when the image starts CMD [ , , ] "npm" "run" "docker-start" Reducing Docker Image The above configuration file will build a Docker image with a size of about 1.3GB, which looks a bit scary because downloading is too time-consuming even with a fast network. That is totally unacceptable. After some research, we learned some tips that help reduce Docker image size. 1. Using Smaller Base Image Docker base image (for example, the above mentioned node:10) is the basic image on which you add layers and create a final image containing your applications. There are of the Node.js image on , and each of them share a different . For example, the version is a more simplified Linux system image that removes some tools like bash, curl etc. to decrease size. multiple versions DockerHub internal environment alpine Based on our needs, we change the base image to and rebuild to reduce the docker image from 1.3GB to 500MB+. So if the docker image you are building is too large, you can . alpine replace the basic image 2. Multi-stage Build build in docker is a new feature introduced in docker 17.05. It is a method to reduce the image size, create a better organization of docker commands, and improve the performance while keeping the dockerfile easy to read and understand. Multi-stage 3. Docker Building Principle In short, multi-stage build is dividing the dockerfile into multiple stages to pass the required artifact from one stage to another and eventually deliver the final artifact in the last stage. This way, our final image won’t have any unnecessary content except our required artifact. Let’s consider an example: node: -alpine as builder .... node: -alpine # Set up the image generated in the first step and name it builder FROM 10 WORKDIR /nebula-web-console # Copy the current project to the image ADD . /nebula-web-console # Start building RUN npm install RUN npm run build # Start the second step build FROM 10 WORKDIR /nebula-web-console # Copy the product of the first step image to the current image. Only one image layer is used here, which saves the number of image layers in the previous building step. COPY --from=builder . /nebula-web-console CMD [ , , ] "npm" "run" "docker-start" 4. .dockerignore Similar to the well known .gitignore that ignores unnecessary (such as document files, git files, node_modules, etc) files when using COPY or ADD command to copy or add files, we can use to specify files to be ignored. .dockerignore 5. Merging Multiple Layers Into One When building a Docker image with a Dockerfile, each operation adds a new layer based on the previous step image. We can use & to merge multiple operations to reduce layers. For example: npm install npm build # The two operations represent two layers RUN RUN run Merge the above command to one: npm install && npm build # It becomes a single layer with & RUN run 6. Regular Front-End Optimization Compress ugly code and remove source code. Finish this step when building image so that the image size is further reduced. Only downloading code needed for production with node_modules Finish this step when deploying, be sure to download only third party dependence code for production: npm install --production Place public source on CDN If the image is expected to run in network environment, place large public files ( pictures and third party libraries, etc.) on the the CDN server so that some resources are separated and the image size is further reduced. … The above suggestions are only for your reference. You can migrate more regular front-end optimizations to the image given that image building itself is an environment for running code. Summary The above is our experience on reducing the Docker image of the . Please leave us a comment if you have any questions. Welcome try Nebula Graph Studio on . Nebula Graph Studio GitHub References How to reduce Docker image size using multi-stage builds Nebula Graph Docker Nebula Graph Studio Also published here .