Membuat docker images dari dockerfile Part-1

Tutorial ini akan membuat docker images lighttpd menggunakan alpine dari dockerfile.

Prerequisties :

  • docker sudah terinstall
  • text editor (ex: vi)

Berikut adalah step - nya

  1. Tetapkan workdir untuk membuat dockerfile, (ex: /home/amet/lighttpd-alpine)
$ pwd
/home/amet/lighttpd-alpine

buat file dockerfile seperti berikut

$ cat dockerfile

# menggunakan image alpine
FROM alpine:latest

MAINTAINER amet doohan <ametdoohan@live.com>

LABEL version="1.0"
LABEL description="lighttpd running on port 80"

# expose pada port 80
EXPOSE 80

# install lighttpd dan konfigurasi (https://wiki.alpinelinux.org/wiki/Lighttpd)
RUN apk add --update --no-cache lighttpd && \
        rm -rf /var/cache/apk/* && \
        lighttpd -t -f /etc/lighttpd/lighttpd.conf && \
        echo "Lighttpd is running..." > /var/www/localhost/htdocs/index.html && \
        addgroup www && \
        adduser -D -H -s /sbin/nologin -G www www

# running lighttpd
ENTRYPOINT ["/usr/sbin/lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"]

atau dapat pull dockerfile dari git saya

git pull https://github.com/ametdoohan/lighttpd-alpine-docker.git
  1. Build image dengan docker build (docker build . -t namaimage:tag)
$ docker build . -t my_alpine_lighttpd:latest
  1. Melihat image yang telah terbuat.
$ docker images

REPOSITORY           TAG                 IMAGE ID            CREATED              SIZE
my_alpine_lighttpd   latest              396e79d82866        About a minute ago   13.7MB
  1. Running container menggunakan image yang telah dibuat, command dibawah running container pada port 8080
$ docker run -d -p 8080:80 --name my_web_server my_alpine_lighttpd:latest
$  docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                  NAMES
c7cc9786f262        my_alpine_lighttpd:latest   "/usr/sbin/lighttpd …"   41 seconds ago      Up 40 seconds       0.0.0.0:8080->80/tcp   my_web_server
  1. Cek apakah webserver telah running
$ curl http://localhost:8080
Lighttpd is running...

web server menggunakan lighttpd yang running pada image base alpine telah running! Tutorial selanjutnya ada di Part-2

Written on January 12, 2020