Rails on Docker

PastLeo @ 5xRuby

What is docker?

docker

Virtualization

分離環境,保持本機的乾淨

Lightweight

Containers running on a single machine share the same operating system kernel

磁碟上/啟動上都很輕快

Portability

外送到府,取貨免付款

docker-in-vm

Installation

Installation

官方網站

hello-world

Hello Docker!

docker run hello-world

cloud2image2container

What the hell just happened?

ruby

外帶 ruby

docker pull ruby

驗貨一下

docker run -it ruby

我要不同版本的

Dockerhub

Ruby on dockerhub

docker run 參數

docker run [options] image[:tag] [command]

Let’s Bootstrap a rails project

練習看看

Useful docker commands

ps [-l|-a], kill, rm

There are a lot more commands, just ask docker: docker

image

How does a image being created?

image

Commit! (Snapshot)

docker commit container_id [image_name]

images, rmi

docker-build

Automation?

Dockerfile => docker build

Let’s create a Dockerfile for the rails project just created

More about Dockerfile

Build it!

docker build -t {image_name} {path_to_context}

Filesystem that stores changes

Shared Layers between images

Cached when build

docker-build

Push! (Upload)

docker push {image}

docker-compose

Multiple Containers and More automation

What if I need mysql/postgresql?

RUN apt-get install postgresql...?

docker-compose

The docker-compose.yml

version: '2'
services:
  services_1:
    ...services_settings...
  services_2:
    ...services_settings...

Service settings

More settings

Let’s use docker-compose to compose rails and postgres!

Postgresql on dockerhub

Up!

One more thing

One-off command, eg. rails c, rake ...

entrypoint

Use this to make rails allow other commands

Thank you for listening







Indexes

Install, Hello Docker, Docker Images, Compose

Rails on Docker

PastLeo @ 5xRuby