docker & fieldaware

20
Adopting Docker Part I Greg Bata / Jakub Jarosz

Upload: jakub-jarosz

Post on 09-Aug-2015

59 views

Category:

Documents


0 download

TRANSCRIPT

Adopting DockerPart I

Greg Bata / Jakub Jarosz

DockerDocker is a platform to develop, ship, and run applications.● Started as internal project at dotCloud● 2013 Opensource version● 14K Images available currently

Similar solutions from the past● LXC containers● OpenVZ

Docker vs VMs

Using / creating imagesChoose and pull an imagedocker pull ubuntu:12.04

$ sudo docker run -t -i ubuntu:12.04 /bin/bash

Manual image creation$ sudo docker commit <container_id> <some_name>$ sudo docker commit -m "Installed htop" -a "Greg" 879182e5a032

admin/ubuntu:12.04

Building an image from a Dockerfile$ mkdir -p /home/user/test/ex1$ cd /home/user/test/ex1$ touch Dockerfile

# FROM ubuntu:14.04# MAINTAINER admin "[email protected]"# ENTRYPOINT echo "Welcome to the docker land!"

$ docker build -t fa:ex1 .$ docker run fa:ex1

Another image from a Dockerfile$ mkdir -p /home/user/test/ex2$ cd /home/user/test/ex2$ touch Dockerfile

FROM ubuntu:14.04MAINTAINER admin "[email protected]"

RUN apt-get updateRUN apt-get install -y htopENTRYPOINT htop

$ docker build -t fa:ex2 .

More advanced exampleFROM ubuntu:14.04

MAINTAINER admin "[email protected]"

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update

RUN apt-get -y install apache2

RUN mkdir /var/lock/apache2

ENV APACHE_RUN_USER www-data

ENV APACHE_RUN_GROUP www-data

ENV APACHE_PID_FILE /var/run/apache2.pid

ENV APACHE_RUN_DIR /var/run/apache2

ENV APACHE_LOCK_DIR /var/lock/apache2

ENV APACHE_LOG_DIR /var/log/apache2

ADD index.html /var/www/html/

EXPOSE 80

CMD ["apache2", "-D", "FOREGROUND"]

Running the 3rd example# Build container$ docker build -t fa:ex3 .

# Run container$ docker run -d --name web -p 80 fa:ex3 /bin/bash -c "while true; do sleep 30;echo 'Webserver is running';done"

Docker image structure

Docker - Sandbox environment

$ git clone [email protected]:<githubname>/fa-docker-sandbox.git

$ cd fa-docker-sandbox

$ vagrant up

$ vagrant ssh

$ sudo docker images

What it does?● create VM (Ubuntu 14.04)● install Docker 1.5● pull ubuntu, postgresql, mysql, redis official images from DockerHub

Dockerfile - base image

# Dockerfile content

# Version 0.0.1

FROM ubuntu:14.04

MAINTAINER Jakub Jarosz "[email protected]"

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

build-essential \

python \

python-dev \

python-pip \

python-virtualenv && \

apt-get clean -y && apt-get autoremove -y

Dockerfile - create base image

# docker build -t "qba73/baseqa:v0.3" .

Sending build context to Docker daemon 2.048 kB

Sending build context to Docker daemon

Step 0 : FROM ubuntu:14.04

---> 5ba9dab47459

Step 1 : MAINTAINER Jakub Jarosz "[email protected]"

<......>

Dockerfile - upload image to DockerHub

# docker push qba73/baseqa:v0.3

The push refers to a repository [qba73/baseqa] (len: 1)

Sending image list

Pushing repository qba73/baseqa (1 tags)

511136ea3c5a: Image already pushed, skipping

<........>

b7144b3ff1b3: Image already pushed, skipping

Pushing tag for rev [b7144b3ff1b3] on {https://cdn-registry-1.docker.io/v1/repositories/qba73/baseqa/tags/v0.3}

Searching for the image/tag in DockerHub

Searching for the image in DockerHub

$ sudo docker search qba73

NAME DESCRIPTION STARS OFFICIAL AUTOM..

qba73/baseqa Base image with python deps 0

qba73/static_web testing & playing with docker 0

Dockerfile - inheriting from base image

# Version 0.0.1

FROM qba73/baseqa:v0.1

MAINTAINER Jakub Jarosz "[email protected]"

ADD . /opt/cps

# Clean pyc & pytest cache

RUN find . -type f -name '*.pyc' -print0 | xargs -0 rm -f \

&& find -name __pycache__ -type d -print0 | xargs -0 rm -rf

RUN cd /opt/cps && pip install -r requirements.txt

WORKDIR /opt/cps

ENTRYPOINT ["py.test", "-v"]

CMD ["cps/tests/tests_pytest/", "--collect-only"]

Build docker image from the base image

$ sudo docker build --no-cache -t "qba73/cpstest1" .

Sending build context to Docker daemon 308.7 MB

Sending build context to Docker daemon

Step 0 : FROM qba73/baseqa:v0.1

---> b7144b3ff1b3

<.....>

List docker local images

$ sudo docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

qba73/cpstest1 latest bc93c9da40ae 10 seconds ago 742.2 MB

qba73/baseqa v0.1 b7144b3ff1b3 7 hours ago 384 MB

Running CPS tests from inside Docker image

$ sudo docker run --name cpsqa_run_1 -t -i qba73/cpstest1

====== test session starts =====

platform linux2 -- Python 2.7.6 -- py-1.4.22 -- pytest-2.5.2 -- /usr/bin/python

collected 9 items / 1 skipped

<Module 'cps/tests/tests_pytest/test_activity_request.py'>

<Function 'test_get_activity_request'>

<Module 'cps/tests/tests_pytest/test_business.py'>

<Function 'test_not_existing_business'>

<Function 'test_create_and_get_business'>

<Function 'test_application_instantiated'>

<......>

===== 1 skipped in 0.09 seconds ====

$

Adopting Docker in FieldAware - Roadmap

● Distributed performance test infrastructure (TheGrinder / Tsung)

● Dockerize projects in dev & test env● Provision containers / build images with Puppet and

Ansible● Introduce Docker in Continuous Integration pipeline:

build, test, deploy