(แทบจะไม่) รู้จักDockerใน 60 วินาที

SiDi Srikk
Sep 9, 2018 · 2 min read

#5ปีแล้วนะไอxัx #Docker was first released in march 2013

ห่อ source codeพร้อมกับ environmentsที่จำเป็น เช่น libs, framework, db ,os เพื่อ ขนย้ายสะดวก ติดตั้งง่าย รวดเร็ว

คล้ายๆ Virtual Machine

เอาไปใช้ทำอะไรกัน

Docker file ตัวอย่าง

1.

FROM ubuntu:12.04 
MAINTAINER Kimbro Staken version: 0.1
ADD ./mysql-setup.sh /tmp/mysql-setup.sh
RUN /bin/sh /tmp/mysql-setup.sh
CMD ["/usr/sbin/mysqld"]

2

FROM node:alpine
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD node index.js
EXPOSE 3000

3

FROM ubuntu
MAINTAINER John Oldman
RUN apt-get install -y python-software-properties python python-setuptools ruby rubygems
RUN add-apt-repository ppa:chris-lea/node.js
RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nodejs
ADD . /var/www
RUN cd /var/www ; npm install
CMD ["/usr/local/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

build คือ โหลดโปรแกรมมาลง รันคำสั่งshell ตามสเปคที่เขียนใน dockerfile

$ docker build -t node-web-app .

run คือ เอาimageมาผูกกับเครื่องhost ตั้งค่าต่างๆเช่น network, storage, ตัวแปรenv

$ docker run -p 49160:8080 -d node-web-app

Docker registry

https://hub.docker.com/explore/ คลังเก็บdocker image คล้ายๆ github npm


Docker เป็นหมู่คณะ ก้ใช้ docker compose

ตัวอย่างไฟด์ docker-compose นี้มี 2 service คือ

version: '3' 
services:
product-service:
build: ./product
volumes:
- ./product:/usr/src/app
ports:
- 5001:80
website:
image: php:apache
volumes:
- ./website:/var/www/html
ports:
- 5000:80
depends_on:
- product-service

SiDi Srikk

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade