- person Penulis:
PT. Tabeldata Informatika
- account_balance_wallet Donasi via:
- Saweria a/n Dimas Maryanto
- lock_open Join Premium Members:
1. Pengenalan Docker 8
2. Docker Registry 3
3. Docker Container CLI 8
1. Docker CLI (Command Line Interface)
2. Management Docker Container
3. Management Docker Images
4. Run a command in a running container
5. Expose services to outside using ports
6. Copying files/content between container and filesystem
7. Logging, Inspect, & Resource Usage Statistics Containers
8. Run a Container using Environtment File
4. Docker Networks 7
5. Docker Volumes 5
6. Dockerfile 15
1. Build Docker Image Overview
2. Usage docker build
3. FROM Instruction
4. Environtment Replacement
5. Copying Resources
6. Excluding files/directories
7. Label Instruction
8. Execution Instruction
9. CMD vs ENTRYPOINT?
10. Exposing Ports
11. User, Volumes and Working Directory
12. Health Check Instruction
13. Multiple Stage Builds
14. Best practices for writing Dockerfiles
15. Best practices for scanning images
7. Study Kasus: Build docker image 14
1. Build specific docker image by programming languages
2. Build Docker Image for Java Webapp
3. Build Java Web using maven-docker-plugin
4. Build docker image for spring-boot
5. Springboot - using Environtment
6. Springboot - where data such as files/images we stored?
7. Springboot - Using Database
8. Build docker image for Angular Project
9. Angular - Access Rest API
10. Angular - Proxy to backend
11. Build docker image for PHP
12. Build Docker image for Laravel Framework
13. Laravel - Using Frontend & Rest API
14. Laravel - Using Database
8. Docker Compose 19
1. Overview of Docker Compose
2. Get started with Docker Compose
3. Overview of docker-compose CLI
4. Compose file specification and syntax
5. Environment variables in Compose
6. Volume in Compose
7. Share data between Containers in Compose
8. Using sshfs for share data in Compose
9. Using NFS for share data in Compose
10. Networking Overview in Compose file
11. Network links in Compose file
12. Specify custom networks in Compose file
13. Dependency between services in Compose file
14. Build docker image using Compose file
15. Using profiles with Compose file
16. Multiple Compose files to Add & Override attribute
17. Example use case of multiple compose files
18. Scale services using compose command
19. Use Compose in production
9. Study Kasus: Docker Compose 7
10. Docker Context 8
11. Study Kasus: Docker for CI 8
1. Overview of Study Cases using docker for CI
2. Setup environment for CI using Gitlab & Nexus OSS
3. The `.gitlab-ci.yml` file
4. Pipeline: PHP deployment using Gitlab CI
5. Pipeline: Java Web deployment using Gitlab CI
6. Pipeline: spring-boot deploy with Gitlab CI
7. Pipeline: Angular deploy with Gitlab CI
8. Pipeline: Laravel deploy with Gitlab CI
12. Docker Machine 7
13. Study Kasus: Ansible for Docker 4
14. Docker Swarm
- Materi: belum tersedia...
15. Study Kasus: Docker Swarm
- Materi: belum tersedia...
16. Docker on Cloud using GCP
- Materi: belum tersedia...
- Lastest Posts
- 17 Jan 23 What is Workload Resources?
- 17 Jan 23 Overview Kubernetes Workloads re...
- 15 Jan 23 Getting started with Transaction...
- 14 Jan 23 Overview of Concurrency Control
- 14 Jan 23 Time your practice (part 3)
- 08 Jan 23 Cleanup Data from Table
- 19 Dec 22 Study Cases: Monolith apps (Lara...
- 28 Nov 22 Overview Study Cases: Pod and Co...
- 19 Nov 22 Pod Disruptions
- 10 Oct 22 Prepared Statement in SQL
Best practices for writing Dockerfiles
This document covers recommended best practices and methods for building efficient images. A Docker image consists of read-only layers each of which represents a Dockerfile instruction. The layers are stacked and each one is a delta of the changes from the previous layer.
Each instruction creates one layer:
FROMcreates a layer from the
COPYadds files from your Docker client’s current directory.
RUNbuilds your application with
CMDspecifies what command to run within the container.
Exclude with .dockerignore
To exclude files not relevant to the build (without restructuring your source repository) use a
.dockerignore file. This file supports exclusion patterns similar to
Use multi-stage builds
Multi-stage builds allow you to drastically reduce the size of your final image, without struggling to reduce the number of intermediate layers and files.
Because an image is built during the final stage of the build process, you can minimize image layers by leveraging build cache.
For example, if your build contains several layers, you can order them from the less frequently changed (to ensure the build cache is reusable) to the more frequently changed:
- Install tools you need to build your application
- Install or update library dependencies
- Generate your application
Each container should have only one concern. Decoupling applications into multiple containers makes it easier to scale horizontally and reuse containers. For instance, a web application stack might consist of three separate containers, each with its own unique image, to manage the web application, database, and an in-memory cache in a decoupled manner.
Installing packages into image
Probably the most common use-case for
RUN is an application of
apt-get. Because it installs packages, the
RUN apt-get command has several gotchas to look out for. Always combine
RUN apt-get update with
apt-get install in the same RUN statement. For example:
Sort multi-line arguments
Whenever possible, ease later changes by sorting multi-line arguments alphanumerically. This helps to avoid duplication of packages and make the list much easier to update. This also makes PRs (Pull Requests) a lot easier to read and review. Adding a space before a backslash (
\) helps as well. Here’s an example from the
Don’t install unnecessary packages
To reduce complexity, dependencies, file sizes, and build times, avoid installing extra or unnecessary packages just because they might be “nice to have.” For example, you don’t need to include a text editor in a database image.
ADD or COPY Instruction
COPY are functionally similar, generally speaking,
COPY is preferred. That’s because it’s more transparent than
COPY only supports the basic copying of local files into the container, while
ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. Consequently, the best use for
ADD is local tar file auto-extraction into the image, as in
ADD rootfs.tar.xz /.