- 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 command in a running container
Hai semuanya di materi kali ini kita akam membahas tentang perintah docker exec
. Diataranya:
- Start bash session
- Run Interactive command
- Working with option args
- Run External program provided by image
Ok, pertama kita lihat dulu dokumentasinya dengan menggunakan perintah:
Seperti berikut:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
Loading personal and system profiles took 711ms.
➜ ~ docker exec -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a
container
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format:
<name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
Start bash session
Kita bisa jalankan dulu containernya, dengan perintah seperti berikut:
Berikut hasilnya:
➜ ~ docker run --name ubuntu_bash -d -i -t ubuntu:21.04
51416e0e051f719667d3596596574338ff2badbec340ca346672761422f2a1d7
➜ ~ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
51416e0e051f ubuntu:21.04 "/bin/bash" 1 second ago Up 3 seconds ubuntu_bash
Sekarang kita coba jalankan perintah untuk membuat file sebagai contoh seperti berikut:
Jika di jalankan maka hasilnya seperti berikut:
➜ ~ ✗ docker exec ubuntu_bash bash -c "mkdir -p /contoh && echo 'Halo saya Dimas Maryanto, sedang belajar docker' > /contoh/test.txt"
➜ ~ ✗ docker exec ubuntu_bash ls -a /contoh
.
..
test.txt
Run Interactive command
Atau kita juga bisa login ke dalam containernya dengan perintah berikut:
Maka hasilnya seperti berikut:
➜ ~ docker exec -it ubuntu_bash bash
root@51416e0e051f:/# ls contoh/
test.txt
root@51416e0e051f:/# cat /contoh/test.txt
Halo saya Dimas Maryanto, sedang belajar docker
Working with option args
Option argument, ini sangat berguna contohnya
--workdir
untuk menentukan lokasi ketika command di execute--user
untuk menetukan siapa yang mengexecute
Sebagai contoh seperti berikut implementasinya:
Jika di jalankan maka hasilnya seperti berikut:
➜ ~ docker exec -i -t -w /contoh -u root ubuntu_bash bash
root@51416e0e051f:/contoh# pwd
/contoh
root@51416e0e051f:/contoh# cat test.txt
Halo saya Dimas Maryanto, sedang belajar docker
root@51416e0e051f:/contoh#
Contoh lainnya, kita coba start container nginx seperti berikut:
Kemudian kita coba jalankan perintah berikut:
Jika dijalankan maka hasilnya seperti berikut:
➜ ~ docker exec -it -u www-data -w /usr/share/nginx webapp bash
www-data@71a009a4f00c:/usr/share/nginx$ pwd
/usr/share/nginx
www-data@9dc0cbceed40:/usr/share/nginx$ ls html/
50x.html index.html
Run External program provided by image
Sekarang kita akan mencoba, menjalankan program/aplikasi contohnya jika menggunakan container maka kita akan mengakses database dengan editor commandline seperti berikut:
Sekarnag kita start dulu, container postgres:9.6
seperti berikut:
Kemudian kita coba login, ke dalam database dengan user postgres
dan menggunakan editor psql
Jika kita coba jalankan, maka hasilnya seperti berikut:
➜ ~ docker exec -u postgres -it postgres_db psql
psql (9.6.21)
Type "help" for help.
postgres=#
Jika kita coba menggunakan user lain, seperti berikut hasilnya:
➜ ~ ✗ docker exec -u root -it postgres_db psql
psql: FATAL: role "root" does not exist
Atau juga kita bisa menggunakan user default wichis root
, yang memparsing user pada user database seperti berikut:
➜ ~ docker exec -it postgres_db psql -U postgres postgres
psql (9.6.21)
Type "help" for help.
postgres=#
Cleanup
Sekarang kita stop semua service yang jalan, dengan perintah seperti berikut:
Yuk simak juga videonya,
Dan jika temen-temen belajar hal baru kali ini jangan lupa buat Like, Subcribe, dan Share ke temen kalian. Terimakasih!!!