├── README.md └── image-optimization ├── caching ├── Dockerfile5 └── Dockerfile6 ├── minimising-layers-count ├── Dockerfile3 └── Dockerfile4 └── multi-stage-builds ├── Dockerfile1 ├── Dockerfile2 ├── env ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # Docker Best Practices 2 | 3 | This repo contians information about best pracrices and optmizations techniques for Docker images. 4 | 5 | ## Documentations 6 | 7 | 1. [How to Reduce Docker Image Size](https://devopscube.com/reduce-docker-image-size/) 8 | -------------------------------------------------------------------------------- /image-optimization/caching/Dockerfile5: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | ENV DEBIAN_FRONTEND=noninteractive 3 | RUN apt-get update -y 4 | RUN apt-get upgrade -y 5 | RUN apt-get install vim -y 6 | RUN apt-get install net-tools -y 7 | RUN apt-get install dnsutils -y 8 | COPY . . 9 | -------------------------------------------------------------------------------- /image-optimization/caching/Dockerfile6: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | COPY . . 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | RUN apt-get update -y 5 | RUN apt-get upgrade -y 6 | RUN apt-get install vim -y 7 | RUN apt-get install net-tools -y 8 | RUN apt-get install dnsutils -y 9 | -------------------------------------------------------------------------------- /image-optimization/minimising-layers-count/Dockerfile3: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | ENV DEBIAN_FRONTEND=noninteractive 3 | RUN apt-get update -y 4 | RUN apt-get upgrade -y 5 | RUN apt-get install vim -y 6 | RUN apt-get install net-tools -y 7 | RUN apt-get install dnsutils -y 8 | -------------------------------------------------------------------------------- /image-optimization/minimising-layers-count/Dockerfile4: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | ENV DEBIAN_FRONTEND=noninteractive 3 | RUN apt-get update -y && \ 4 | apt-get upgrade -y && \ 5 | apt-get install --no-install-recommends vim net-tools dnsutils -y 6 | -------------------------------------------------------------------------------- /image-optimization/multi-stage-builds/Dockerfile1: -------------------------------------------------------------------------------- 1 | FROM node:16 2 | COPY . . 3 | RUN npm install 4 | -------------------------------------------------------------------------------- /image-optimization/multi-stage-builds/Dockerfile2: -------------------------------------------------------------------------------- 1 | FROM node:16 as build 2 | 3 | WORKDIR /app 4 | COPY package.json index.js env ./ 5 | RUN npm install 6 | 7 | FROM node:alpine as main 8 | 9 | COPY --from=build /app / 10 | EXPOSE 8080 11 | CMD ["index.js"] 12 | -------------------------------------------------------------------------------- /image-optimization/multi-stage-builds/env: -------------------------------------------------------------------------------- 1 | PORT=3000 2 | -------------------------------------------------------------------------------- /image-optimization/multi-stage-builds/index.js: -------------------------------------------------------------------------------- 1 | const dotenv=require('dotenv'); 2 | dotenv.config({ path: './env' }); 3 | 4 | dotenv.config(); 5 | 6 | const express=require("express"); 7 | const app=express(); 8 | 9 | app.get('/',(req,res)=>{ 10 | res.send(`Learning to Optimize Docker Images with DevOpsCube!`); 11 | }); 12 | 13 | 14 | app.listen(process.env.PORT,(err)=>{ 15 | if(err){ 16 | console.log(`Error: ${err.message}`); 17 | }else{ 18 | console.log(`Listening on port ${process.env.PORT}`); 19 | } 20 | } 21 | ) 22 | -------------------------------------------------------------------------------- /image-optimization/multi-stage-builds/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "dotenv": "^10.0.0", 14 | "express": "^4.17.2" 15 | } 16 | } 17 | --------------------------------------------------------------------------------