Pengantar Docker
Tim Sangster
Software Engineer @ DataCamp
Image hello-world mencetak teks lalu berhenti.
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon created a new container from the hello-world image which runs the
executable that produces the output you are currently reading.
3. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
Sebuah image dengan python dapat menjalankan python saat startup.
docker run python3-sandbox
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
...
....
>>> exit()
repl@host:/#
CMD <shell-command>
Instruksi CMD:
Menjalankan aplikasi untuk workflow atau yang menerima koneksi luar.
CMD python3 my_pipeline.py
CMD postgres
Menjalankan skrip yang pada gilirannya memulai beberapa aplikasi
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Image yang lebih umum perlu perintah start yang lebih umum.
Menjalankan image
docker run <image>
Menjalankan image dengan perintah start kustom
docker run <image> <shell-command>
Menjalankan image secara interaktif dengan perintah start kustom
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Penggunaan | Instruksi Dockerfile |
|---|---|
| Menambahkan perintah shell yang dijalankan saat kontainer dimulai dari image. | CMD <shell-command> |
| Penggunaan | Perintah Shell |
|---|---|
| Menimpa CMD yang disetel di image | docker run <image> <shell-command> |
| Menimpa CMD di image dan menjalankan secara interaktif | docker run -it <image> <shell-command> |
Pengantar Docker