1. Docker

1.1. Instalacja

1.2. CLI - Command Line Interface

1.2.1. Pierwsze polecenia

docker run hello-world
docker run -it ubuntu bash

1.2.2. Przydatne polecenia

docker run bash
docker ps -a
docker exec -u 0 -it CONTAINER_NAME bash
docker images
docker rm IMAGE

1.3. Building Images

docker build -t docker .

1.4. Container linking

Containers can be linked to another container’s ports directly using -link remote_name:local_alias in the client’s docker run. This will set a number of environment variables that can then be used to connect:

docker run --rm -t -i --link pg_test:pg eg_postgresql bash

1.5. Volumes

A data volume is a specially-designated directory within one or more containers that bypasses the Union File System. Data volumes provide several useful features for persistent or shared data:

  • Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization. (Note that this does not apply when mounting a host directory.)
  • Data volumes can be shared and reused among containers.
  • Changes to a data volume are made directly.
  • Changes to a data volume will not be included when you update an image.
  • Data volumes persist even if the container itself is deleted.

Data volumes are designed to persist data, independent of the container’s life cycle. Docker therefore never automatically deletes volumes when you remove a container, nor will it “garbage collect” volumes that are no longer referenced by a container [Docker].


You can also use the VOLUME instruction in a Dockerfile to add one or more new volumes to any container created from that image.


1.5.1. Mounting directories

docker run -v <host path>:<container path>[:FLAG]
docker run --detach -P --name web -v /developer/myproject:/var/www training/webapp python app.py
docker run --detach -P --name web -v /developer/myproject:/var/www:ro training/webapp python app.py

1.5.2. Tworznie volumenów

docker volume create -d flocker --opt o=size=20GB my-named-volume
docker run --detach -P -v my-named-volume:/webapp --name web training/webapp python app.py

1.5.3. Mounting files

docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash

1.5.4. Volume container

docker create -v /dbdata --name dbstore training/postgres /bin/true
docker run --detach --volumes-from dbstore --name db1 training/postgres

1.6. Docker Hub

docker run docker/whalesay cowsay boo

1.6.1. Publikowanie

docker login
docker tag 7d9495d03763 yourusername/docker-whale:latest
docker push yourusername/docker-whale
docker image remove 7d9495d03763
docker run yourusername/docker-whale

1.6.2. Dockerfile

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
docker build -t docker-whale .
docker images
docker run docker-whale
FROM      ubuntu
LABEL Description="This image is used to start the foobar executable" Vendor="ACME Products" Version="1.0"
RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server
FROM ubuntu
RUN echo foo > bar

FROM ubuntu
RUN echo moo > oink
FROM debian:stable
RUN apt-get update && apt-get install -y --force-yes apache2
EXPOSE 80 443
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]

# An ENTRYPOINT allows you to configure a container that will run as an executable.
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

1.7. Docker-compose

Compose is a tool for defining and running multi-container Docker applications.

FROM python:3.6
RUN mkdir /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
version: '2'
    image: postgres
    build: .
    command: python manage.py runserver
      - .:/code
      - "8000:8000"
      - db
docker-compose run web django-admin.py startproject composeexample .
sudo chown -R $USER:$USER .
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
docker-compose up
docker-machine ip MACHINE_NAME

1.8. Zadania do rozwiązania

1.8.1. Ehlo World

  • Zainstaluj Docker
  • Czym różni się Docker od Vagrant?
  • Wyświetl Ehlo World! z wnętrza kontenera Docker
  • Wyświetl listę działających kontenerów Docker

Pokaż rozwiązanie - Ehlo World

1.8.2. Create container and run

Pokaż rozwiązanie - Create container and run

1.8.3. Dockerfile

  • Stwórz kontener dla PostgreSQL

Pokaż przykładowy ``Dockerfile``

1.8.4. Docker Compose

Pokaż rozwiązanie