Laman ini menunjukkan bagaimana cara menggunakan Show
Sebelum kamu memulaiKamu harus memiliki klaster Kubernetes, dan perangkat baris perintah kubectl juga harus dikonfigurasikan untuk berkomunikasi dengan klastermu. Jika kamu belum memiliki klaster, kamu dapat membuatnya dengan menggunakan , atau kamu juga dapat menggunakan salah satu dari tempat mencoba Kubernetes berikut ini: Untuk melihat versi, tekan 0.Mendapatkan sebuah shell untuk masuk ke sebuah ContainerDalam latihan ini, kamu perlu membuat Pod yang hanya memiliki satu Container saja. Container tersebut menjalankan image nginx. Berikut ini adalah berkas konfigurasi untuk Pod tersebut: Buatlah Pod tersebut:
Pastikan bahwa Container dalam Pod berjalan:
Dapatkan shell untuk masuk ke dalam Container:
Catatan: Simbol tanda hubung ganda "--" digunakan untuk memisahkan antara argumen perintah yang ingin kamu eksekusi pada Container dan argumen dari kubectl itu sendiri. Di dalam shell kamu, perlihatkan isi dari direktori root: Di dalam shell kamu, cobalah perintah-perintah yang lainnya. Berikut beberapa contohnya:
Lihat kembali berkas konfigurasi untuk Pod kamu. Pod memiliki volume 1, dan Container melakukan pemasangan (mounting) untuk volume tersebut pada 2.Pada shell kamu, buatlah berkas 3 dalam direktori 2:
Pada shell kamu, kirimkan sebuah permintaan (request) GET ke server nginx.
Keluarannya akan menunjukkan teks yang kamu tulis pada berkas 3.Setelah kamu selesai dengan shell kamu, ketiklah 6.Menjalankan perintah individu di dalam sebuah ContainerPada jendela (window) perintah biasa, bukan pada shell kamu di dalam Container, lihatlah daftar variabel lingkungan (environment variable) pada Container yang sedang berjalan:
Cobalah dengan menjalankan perintah lainnya. Berikut beberapa contohnya:
Membuka sebuah shell ketika sebuah Pod memiliki lebih dari satu ContainerJika sebuah Pod memiliki lebih dari satu Container, gunakanlah 7 atau 8 untuk menentukan Container yang dimaksud pada perintah kubectl exec . Sebagai contoh, misalkan kamu memiliki Pod yang bernama my-pod, dan Pod tersebut memiliki dua Container yang bernama main-app dan helper-app. Perintah berikut ini akan membuka sebuah shell ke Container dengan nama main-app. In this tutorial, we'll learn how to run multiple Docker containers with an interactive shell. First, we'll run a Docker container using the simple docker run command. Later, we'll run the same Docker container with the docker-compose command. 2. Docker and Docker ComposeDocker containers allow developers to package applications that work seamlessly across different environments. In fact, a typical deployment of a web application in a production environment may require several services:
In such situations, Docker Compose is a very handy tool. Docker Compose is mainly used to run multiple containers as a single service while maintaining a smooth connection between the containers. 3. Understanding Docker ComposeTo run a Docker container using the docker-compose command, we need to add all the configurations to the single docker-compose.yml configuration file. Importantly, one of the key benefits of using docker-compose over the normal docker run command is the configuration consolidation in a single file, which both machines and humans can read. Let's create a simple docker-compose.yml to show how to run Docker containers using the docker-compose up command:
Here, we used tomcat as the base image and exposed port 8080 on the host machine. To see it in action, let's build and run this image using the docker-compose up command:
Critically, we should run the above command from the directory containing the docker-compose.yml file. In the above output, we can see that the dockercontainers_server_1 is up and running. However, an issue with this approach is that once we exit the above shell, the container will also stop. To run the Docker container for the long run, we need to run it with an interactive shell. 4. Interactive Shell in DockerThe interactive mode in Docker allows us to execute commands while the container is in a running state. To run the Docker container in interactive mode, we use the -it option. Further, we attach both the STDIN and STDOUT channels to our terminal with the -it flags. Docker Compose uses a single-host deployment that has multiple benefits:
Let's now run the tomcat container from earlier using docker-compose with an interactive shell:
In this case, we added the stdin_open and tty options in the docker-compose.yml file so that we can have an interactive shell with the docker-compose setup. Of course, to access the Docker container, we need first to run the container using the below command:
Now, we can get an interactive shell of the running docker-compose service:
Note how we use the service name and not the container name. Finally, we successfully log into the container with the above command. 5. ConclusionIn this article, we demonstrated how to get an interactive shell using the docker-compose command. First, we learned how to run a Docker container using docker-compose. After that, we explored the same with an interactive shell using the docker exec command and the docker-compose YAML configuration. Bagaimana cara kerja docker?Cara kerja Docker
Docker berfungsi dengan menyediakan cara standar untuk menjalankan kode Anda. Docker adalah sistem operasi untuk kontainer. Mirip dengan cara mesin virtual memvirtualisasi (menghilangkan kebutuhan untuk secara langsung mengelola) perangkat keras server, kontainer memvirtualisasi sistem operasi server.
Langkah Install docker?Cara Install Docker. Step 1: Download Docker untuk Windows. Pertama download dulu Installer Docker Desktop di website resminya: ... . Step 2: Mulai Install Docker di Windows. ... . Step 3: Konfigurasi. ... . Step 4: Proses Instalasi. ... . Step 5: Instalasi Selesai. ... . Step 6: Terima Agreement. ... . Step 7: Install WSL 2.. Apa yang dimaksud dengan container docker?Penjelasan Singkat tentang Container Docker
Docker container adalah sebuah paket software yang berisi semua dependensi yang diperlukan untuk menjalankan aplikasi tertentu. Semua konfigurasi dan instruksi untuk memulai atau menghentikan container diperintahkan oleh sebuah komponen yang disebut 'image Docker'.
Apa itu image di docker?Docker image — Kumpulan file yang menunjang sebuah aplikasi. Docker container — Wadah untuk mengemas dan menjalankan aplikasi. Wadah ini mencakup kode, runtime, system tools, dan pengaturan. Container hanya bisa mengakses resource yang telah ditentukan dalam Docker image.
|