Docker

Andre Septiano
3 min readMay 21, 2022

--

Docker Illustration

Dalam mengembangkan sebuah perangkat lunak tak hanya ada Frontend dan Backend saja, namun juga terdapat bagian lain yang bernama DevOps. DevOps merupakan singkatan dari Development and Operation. Mengutip dari dicoding, DevOps adalah sebuah prinsip developer untuk mengkoordinasikan antar tim yaitu tim development dengan tim operations dengan efektif dan efisien. Salah satu tools yang digunakan dalam DevOps adalah Docker.

Docker

Berikut adalah overview dari docker berdasarkan dokumentasinya:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

Dengan docker, kita tidak perlu mengatur dan menginstall hal-hal yang diperlukan seperti webserver, database, library scara manual pada server. Sebagai gantinya, semuanya di-bundle ke dalam sebuah package yang kemudian package inilah yang akan di-deploy ke server sehingga menjadi lebih mudah.

Keuntungan Menggunakan Docker

Dengan menggunakan docker, masalah seperti ilustrasi di atas dapat diatasi, dimana setiap mesin memiliki masalah tersendiri walaupun para developer saling berbagi aplikasi. Dengan menggunakan docker, aplikasi akan berjalan sebagaimana mestinya pada setiap mesin dengan bundling dan mengisolasi aplikasi yang dikembangkan ke dalam docker.

Berikut adalah beberapa terminologi penting dari Docker:

  • Docker Image
    Komponen yang berisi informasi seperti configurations, dependencies, operating system, dan source code yang diperlukan untuk menjalankan aplikasi. Docker Image dapat dikatakan sebagai read-only template dengan instruksi tertentu untuk membuat Docker Container.
  • Docker Container
    Instance dari sebuah image yang dapat dijalankan.
  • Dockerfile
    Scriptfile yang berisi command-command yang diperlukan dalam membuat sebuah docker image.

Alasan Kenapa Harus Menggunakan Docker

Berikut adalah alasan menggunakan docker mengutip dari dokumentasi docker:

  1. Fast, consistent delivery of your applications
    Docker streamlines the development lifecycle by allowing developers to work in standardized environments using local containers which provide your applications and services. Containers are great for continuous integration and continuous delivery (CI/CD) workflows.
  2. Responsive deployment and scaling
    Docker’s container-based platform allows for highly portable workloads. Docker containers can run on a developer’s local laptop, on physical or virtual machines in a data center, on cloud providers, or in a mixture of environments.
    Docker’s portability and lightweight nature also make it easy to dynamically manage workloads, scaling up or tearing down applications and services as business needs dictate, in near real time.
  3. Running more workloads on the same hardware
    Docker is lightweight and fast. It provides a viable, cost-effective alternative to hypervisor-based virtual machines, so you can use more of your compute capacity to achieve your business goals. Docker is perfect for high density environments and for small and medium deployments where you need to do more with fewer resources.

Contoh implementasi Docker

Berikut adalah contoh implementasi docker pada kelompok PPL kami

FROM python:3.10-slim as dev
ENV PYTHONBUFFERED=1

RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential libpq-dev && \
rm -rf /var/lib/apt/lists/*


RUN pip install pipenv
COPY Pipfile /app/

WORKDIR /app

RUN pipenv lock --keep-outdated --requirements > requirements.txt && \
pip install --no-cache-dir -r requirements.txt

COPY ./script .
RUN chmod +x *.sh

FROM python:3.10-slim as prod
ENV PYTHONBUFFERED=1

RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential libpq-dev && \
rm -rf /var/lib/apt/lists/*


RUN pip install pipenv
COPY Pipfile /app/

WORKDIR /app

RUN pipenv lock --keep-outdated --requirements > requirements.txt && \
pip install --no-cache-dir -r requirements.txt

EXPOSE 8000
COPY ./script .
RUN chmod +x *.sh
COPY ./evisem_backend .

ENTRYPOINT ["./entrypoint.sh"]
CMD ["./start.sh", "server"]

Referensi

--

--