Sebelum mengikuti tutorial di bawah ini, anda wajib menginstall docker di laptop anda
Buat folder yang berisi file index.js
lalu di index.js buat kode console.log("Hallo Docker");
1. Buat dockerfile di root project
Contoh sederhana untuk Dockerfile :
FROM node:20
WORKDIR /app
COPY index.js ./
CMD ["node", "index.js"]
2. Build image via dockerfile
- docker build -t nama_app:versi_app .
contoh : docker build -t myenv .
Catatan jika kode versi tidak di tulis saat menjalankan perintah, maka nama versi menjadi latest
3. Build ulang image via dockerfile [ optional jika file index.js ada perubahan ]
- docker build --no-cache -t nama_app:versi_app
contoh : docker build --no-cache -t myapp:v0.1
4. Jalankan image menjadi container
- docker run --name nama_container -d nama_image_yang_sudah_dibuat
contoh : docker run --name my-app -d myapp:v0.1
5. Cek log output setelah di run
- docker logs nama_container
contoh : docker logs myapp:v0.1
6. Push ke docker hub
- docker build -t your_username/my-app:v0.1 .
- docker tag your_username/my-app:v0.1 your_username/my-app:v0.1
- docker push your_username/my-app:v0.1
Tutorial ini hanya menjalankan index.js menggunakan nodejs dengan output console log Hallo Docker