Home Building Docker Images with Dockerfiles
Post
Cancel

Building Docker Images with Dockerfiles

Dockerfile adalah skrip yang berisi step atau instruksi untuk membuat image Docker. Instruksi ini sebenarnya adalah sekelompok perintah yang dijalankan secara otomatis di lingkungan Docker untuk membuat image Docker tertentu.

Install Docker

1
2
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Build a Docker Image

Sebagai contoh, kali ini akan mencoba membuat image nfs-server dengan alpine

Clone repository github

1
git clone https://github.com/sjiveson/nfs-server-alpine.git

Masuk ke direktori nfs-server-alpine lalu pastikan Dockerfile ada di dalam folder

1
2
cd nfs-server-alpine
cat Dockerfile

Selanjutnya build image dengan perintah

1
docker build -t nfs-server-alpine .

Pada option -t nfs-server-alpine dapat diganti dengan nama image Anda sendiri

Tunggu proses build selesai lalu cek image

1
docker images
REPOSITORY                      TAG       IMAGE ID       CREATED       SIZE
nfs-server-alpine               latest    b480353d8144   2 hours ago   67.8MB

Upload image to registry

Image yang sudah terbuat sebelumnya dapat Anda upload ke registry docker untuk digunakan lagi di host docker yang lain tanpa perlu build kembali.

Login ke registry menggunakan akun Docker. Jika belum punya silakan daftar terlebih dahulu.

1
docker login

Buat tag image dari source image yang sudah dibuat

1
docker tag nfs-server-alpine:latest username/nfs-server-alpine:latest

Push ke registry dengan perintah

1
docker push username/nfs-server-alpine:latest

Test dengan docker pull

1
docker pull username/nfs-server-alpine:latest
latest: Pulling from username/nfs-server-alpine
Digest: sha256:9eb7ba93371a84f257842f375dc2df10c63cb2e198a4283d4543867e9564ee1f
Status: Image is up to date for username/nfs-server-alpine:latest
docker.io/username/nfs-server-alpine:latest
This post is licensed under CC BY 4.0 by the author.