What is Docker?

  • It's a project
  • It's a tool
  • It's open source

So, docker is a virtualization tool?

Essential 5 differences:

  • Kernel
  • Issolation
  • Resources
  • Performance
  • Cache/Time

How does docker work?

images

images

### FROM clause tries to find a local Docker image with that name to build a previous environment, if not, Docker will pull it from DockerHub site if it exists
FROM ubuntu:18.04

### ARG syntax is expecting an argument which is referred in other image
### ENV syntax sets a variable value inside the image build
# RVM version to install
ARG RVM_VERSION=stable
ENV RVM_VERSION=${RVM_VERSION}

# RMV user to create
ARG RVM_USER=rvm
ENV RVM_USER=${RVM_USER}

# Install recommended
ENV DEBIAN_FRONTEND=noninteractive
### RUN syntax execute following bash command
RUN apt update \
    && apt install -y \
       curl \
       git \
       gnupg2 \
       locales \
       tzdata \
    && rm -rf /var/lib/apt/lists/*

# Use en_US.UTF-8 as our locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Install RVM with gpg (https://rvm.io/rvm/security)
RUN gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN echo progress-bar >> ~/.curlrc
RUN curl -sSL https://get.rvm.io | bash -s ${RVM_VERSION} --ignore-dotfiles
RUN sed -i 's/^mesg n/tty -s \&\& mesg n/g' /root/.profile
RUN echo "source /usr/local/rvm/scripts/rvm" >> /etc/bash.bashrc

### SHELL syntax starts a shell during the image build, login shell in that case
# Allow 'rvm' in RUN commands
SHELL ["/bin/bash", "-l", "-c"]
FROM instructure/core:xenial
MAINTAINER Instructure

USER root
RUN apt-get update \
 && apt-get install -y \
      autoconf \
      automake \
      bison \
      gawk \
      sqlite3 \
      make \
      imagemagick \
      libbz2-dev \
      libcurl4-openssl-dev \
      libevent-dev \
      libffi-dev \
      libgdbm-dev \
      libglib2.0-dev \
      libgmp-dev \
      libjpeg-dev \
      libmagickcore-dev \
      libmagickwand-dev \
      libmysqlclient-dev \
      libncurses-dev \
      libpq-dev \
      libreadline-dev \
      libsqlite3-dev \
      libssl-dev \
      libxml2-dev \
      libxslt-dev \
      libyaml-dev \
      zlib1g-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/src/app && chown docker:docker /usr/src/app

USER docker

# Install RVM
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys \
      409B6B1796C275462A1703113804BB82D39DC0E3 \
      7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
 && curl -sSL https://get.rvm.io | bash -s -- --autolibs=read-fail stable \
 && echo 'bundler' >> /home/docker/.rvm/gemsets/global.gems \
 && echo 'rvm_silence_path_mismatch_check_flag=1' >> ~/.rvmrc

SHELL ["/bin/bash", "-lc"]
CMD ["/bin/bash", "-l"]
docker build -t rvm .

Building images

docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
rvm                 latest              673750f72990        15 minutes ago      190MB
ubuntu              18.04               c3c304cb4f22        2 weeks ago         64.2MB
docker images ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Show all images

Show running images

Containers

docker run -it --name rvm_container rvm

root@349691e0b63c:/# 

Run container

$ docker container ls                                                 

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
349691e0b63c        rvm                 "/bin/bash"         5 minutes ago       Up 5 minutes                            rvm_container

Check running containers

VOLUMES

docker volume rvm_gems

Create volume for container

docker volume inspect rvm_gems                                                                                  ‹system: ruby 2.6.3p62›
[
    {
        "CreatedAt": "2020-05-09T13:01:47Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/rvm_gems/_data",
        "Name": "rvm_gems",
        "Options": null,
        "Scope": "local"
    }
]

Check created volume

docker run -it --name rvm_container --volume rvm_gems:/gems rvm

DOCKER COMPOSE

Made with Slides.com