- person Penulis:
-
Dimas Maryanto
PT. Tabeldata Informatika
- account_balance_wallet Donasi via:
- Saweria a/n Dimas Maryanto
- lock_open Join Premium Members:
- Udemy.com
-
Daftar Materi
-
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
- 09 Apr 23 Working with Deployment object
- 26 Feb 23 Study cases: Microservice apps (...
- 05 Feb 23 Welcome to the Nutanix HCF (Hybr...
- 04 Feb 23 Silabus SRE - Nutanix AHV: Pemul...
- 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
Run a Container using Environtment File
Hai semuanya, di materi kali ini kita akan membahas tentang Environment Variables pada Docker diantaranya:
- What is Environtment Variable
- Create Docker Container using Env Variables
- Using Env Files for Create Docker Containers
What is Environtment Variable
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
Create Docker Container using Env Variables
Untuk menggunakan Environtment Variable. Kita harus check di dokumentasi docker image yang akan kita gunakan apakah menyediakan Environtment Variable atau tidak. Misalnya sebagai contoh kita lihat ke dokumentasi docker image postgres. Di dokumentasi tersebut kita di sediakan beberapa variable contohnya POSTGRES_PASSWORD
, POSTGRES_USER
, POSTGRES_DB
dan lain-lain.
Nah untuk cara menggunakannya. Kita bisa menggunakan perintah berikut untuk membuat containernya:
For Bash Script:
For Powershell Script:
Jika di jalankan maka hasilnya seperti berikut:
➜ docker container run `
--name postgres_env `
-e POSTGRES_USER=root `
-e POSTGRES_DB=example_db `
-e POSTGRES_PASSWORD=password `
-d `
postgres:12.6
a2a1dad25d91c8ed594b47a532c21aeecbe4bca00e3f4a4cc9aea29eee6a04fb
➜ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2a1dad25d91 postgres:12.6 "docker-entrypoint.s…" 14 seconds ago Up 13 seconds 5432/tcp postgres_env
➜ docker container inspect postgres_env
[ "POSTGRES_USER=root",
"POSTGRES_DB=example_db",
"POSTGRES_PASSWORD=password",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/12/bin",
"GOSU_VERSION=1.12",
"LANG=en_US.utf8",
"PG_MAJOR=12",
"PG_VERSION=12.6-1.pgdg100+1",
"PGDATA=/var/lib/postgresql/data"
]
➜ 04g-env ✗ docker exec -it postgres_env psql -U root example_db -W
Password: #input password then enter, that will login to postgres db
psql (12.6 (Debian 12.6-1.pgdg100+1))
Type "help" for help.
example_db=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+-------+----------+------------+------------+-------------------
example_db | root | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | root | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c/root +
| | | | | root=CTc/root
template1 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c/root +
| | | | | root=CTc/root
(4 rows)
example_db=#
Jadi dengan Env Variable, tersebut kita meng-override variable default yang ada pada docker image tersebut
Using Env Files for Create Docker Containers
Selain menggunakan parameter arguments -e
atau --env
kita juga menyimpanya dengan menggunakan file, Orang-orang sering mengebutunya Env-File dengan menggunakan format VAR=VALUE
. Berikut adalah basic rules untuk menulis file env
:
- Nama file, biasanya menggunakan
.env
,.env.prod
,.env.dev
dan lain-lain. - Lines beginning with # are processed as comments and ignored.
- Blank lines are ignored.
- There is no special handling of quotation marks. This means that they are part of the VAL.
Berikut adalah contohnya, berdasarkan container yang telah kita buat sebelumnya:
Kemudian untuk menjalankan containernya, kita bisa menggunakan perintah berikut:
Jika di jalankan maka hasilnya seperti berikut:
➜ 04g-env ls
Directory: C:\Users\dimasm93\Workspaces\Example\docker\04-docker-cli\04g-env
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 5/18/2021 8:17 PM 75 .env
➜ 04g-env cat .env
POSTGRES_PASSWORD=password
POSTGRES_USER=root
POSTGRES_DB=example_db
➜ 04g-env docker run --name postgres_envfile --env-file .env -d postgres:12.6
c3a464b6722a9cab79abf1ceff5fe2ed7d35c9b527fc8319f50202899aa7cdd0
➜ 04g-env docker container inspect postgres_envfile
[
"POSTGRES_PASSWORD=password",
"POSTGRES_USER=root",
"POSTGRES_DB=example_db",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/12/bin",
"GOSU_VERSION=1.12",
"LANG=en_US.utf8",
"PG_MAJOR=12",
"PG_VERSION=12.6-1.pgdg100+1",
"PGDATA=/var/lib/postgresql/data"
]
Jadi kesimpulanya, Dengan menggunakan Environtment Variable. Kita bisa meng-override nilai default-nya kemudian di digunakan untuk tujuan tertentu.
Yuk simak juga videonya,
Dan jika temen-temen belajar hal baru kali ini jangan lupa buat Like, Subcribe, dan Share ke temen kalian. Terimakasih!!!