Docker basics for

a local development

Evgeniy Melnikov

www.angarsky.ru

@angarsky

What is the docker?

Apache

PHP

MySQL

2.2

5.6

5.0.67

Ubuntu / Windows / OS X

What is the docker?

Ubuntu / Windows / OS X

Ubuntu

Ubuntu

Ubuntu

PHP

Apache

MySQL

What is the docker?

Ubuntu / Windows / OS X

+

Docker

Apache:2.2

Ubuntu

MySQL:5.0.67

Ubuntu

PHP:5.6

Ubuntu

NGINX:1.14.1

Ubuntu

  • experience in an administration of Unix-like systems
  • understanding of how services work, how to manage a configuration
  • strong Google search skills

Docker

Good or evil?

docker terminology

image  & container

Dockerfile

FROM nginx:1.14.1

RUN apt-get update && apt-get install -y vim

COPY docker/nginx/nginx.conf /etc/nginx/

WORKDIR /var/www

host OS

VOLUME

NGINX

PHP

???

PORT EXPOSe

NGINX

MYSQL

:80
:3306
:8000, :3306

Docker-compose.yml

version: '3'

services:
  training-nginx:
    build:
      context: .
      dockerfile: Dockerfile-nginx
    ports:
    - "8080:80"
    volumes:
    - ./:/var/www
    depends_on:
    - training-php
    container_name: nginx

  training-php:
    image: php:7.1.24-fpm
    volumes:
    - ./:/var/www
    container_name: php-fpm

what kind of containers do we need?

containers list

?

NGINX

PHP

MYSql

redis

PMA

SOLR

 — where i can get these containers?

 — Docker hub!   

Dockerfile

FROM php:5.6.36-fpm

# Install Redis
RUN apt-get update \
 && pecl install redis

Commit to Github

Build on the Docker Hub

Docker image

Users pull the image

Users run a container

how does the docker hub work?

Dockerfile

FROM php:5.6.36-fpm

# Install Redis
RUN apt-get update \
 && pecl install redis

Build an image

locally

Run a container

from the image

Can i build images locally?

it's time to run!

run your container

docker build --file Dockerfile-name --tag my_image_name .
docker run -d -p 8080:80 --volume $(pwd):/var/www --name my_nginx my_image_name

Build an image:

run a container from your image:

docker run -d -p 8080:80 --volume $(pwd):/var/www --name my_nginx nginx:1.14.1

RUN A CONTAINER FROM external image:

Monitor your containers

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                      NAMES
11                  sites_angarsky-php     "docker-php-entryp..."   3 months ago        Up 2 weeks          9000/tcp                                   php-fpm
22                  sites_angarsky-nginx   "nginx -g 'daemon ..."   8 months ago        Up 2 weeks          0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
33                  sites_angarsky-redis   "docker-entrypoint..."   8 months ago        Up 2 weeks          6379/tcp                                   redis
44                  sites_angarsky-db      "docker-entrypoint..."   8 months ago        Up 2 weeks          3306/tcp                                   db
docker ps

list of containers:

CONTAINER           CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
11                  3.09%               205.6MiB / 300MiB   68.55%              45.2GB / 13.9GB     13.1GB / 496MB      5
22                  0.00%               44.56MiB / 200MiB   22.28%              419MB / 565MB       680MB / 54.7MB      8
33                  0.15%               18.32MiB / 100MiB   18.32%              5.6GB / 25.1GB      27.2MB / 0B         4
44                  0.63%               216MiB / 250MiB     86.39%              6.27GB / 15.9GB     1.21GB / 504GB      34
docker stats

resource usage statistics:

trobleshooting

docker exec -it nginx /bin/bash

connect to a container:

docker logs nginx

read  CONTAINER's logs:

docker cp db:/var/log/mysql/mysql-slow.log ~/sites/logs/

copy a file from a container to a host:

let's practice!

github.com/DrupalSquad/traning-december18
slides.com/angarsky/ds-docker-basics

06 December 2018

Made with Slides.com