an introduction to docker · docker save these tar files can be copied to other systems to run...

26
An introduction to Docker Bert Vandenbroucke [email protected]

Upload: others

Post on 10-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

An introduction to Docker

Bert [email protected]

Page 2: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Problem introduction

Where does your application run?

“The Cloud”

Slide 2 of 26

Page 3: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Problem introduction

Different systems have:

• different operating systems

• different hardware

• different compilers/libraries...

How do you make sure that an application/workflow that runs on your computer will run on another computer?

Slide 3 of 26

Page 4: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Traditional solution

Test on other systems:

• install a dual boot system, buy a new laptop...

• run another system in VirtualBox (system emulation)

• manually install different compilers, libraries... and figure out how to use/link them correctly

Slide 4 of 26

Page 5: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

New solution

Container: isolated environment that runswithin your operating system

Slide 5 of 26

Page 6: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Containers: advantages

• Lightweight: only relevant libraries and applications, no complete OS

• Portable: can be saved (image) and loaded on another system

• Isolated from host OS

• Large number of images (100,000+) in online container registries on hub.docker.com

Slide 6 of 26

Page 7: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Use case 1: remote analysis

Create analysis scriptsand pipeline on yourown computer

Run the actual analysisin the same environmenton a large cluster

Slide 7 of 26

Page 8: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Use case 2: code testing

Check that code works with differentcompilers and libraries on the same computer

GCC 4.8Python 2.7

GCC 5.0Python 3.0

Clang 3.0Python 2.7

Slide 8 of 26

Page 9: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Use case 3: student labs

Create lab scriptson your owncomputer

Students do the lab inthe same environment

Slide 9 of 26

Page 10: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Docker setup

Detailed instructions for various platforms available: https://docs.docker.com/install/

Slide 10 of 26

Page 11: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Docker overview

Creating a container

Loading and running a container

Saving a container

Slide 11 of 26

Page 12: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Docker overview

Creating a container

Loading and running a container

Saving a container

Slide 12 of 26

Page 13: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Creating a container

A new container is always based on an existing base container:

• contains basic OS binaries

• contains basic libraries

• can contain specific libraries (e.g. specific Python version)

• should be available from an online registry

Slide 13 of 26

Page 14: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Creating a container

Basic command: docker build

Requires a Dockerfile to be present:

• specifies a base container

• sets up new libraries and applications

• creates custom folders and files

• copies files from the host to the container

Slide 14 of 26

Page 15: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Creating a container

Example Dockerfile that sets up a default code development environment based on Ubuntu

FROM ubuntu

RUN apt-get update && \

apt-get install gcc git -y

base container

install GCC and git

automatically answer "yes" when apt-get asks for permission

to install new packages

Slide 15 of 26

Page 16: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Creating a container

*first run of command will produce more output

Slide 16 of 26

Page 17: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Creating a container

Check that image was created

Slide 17 of 26

Page 18: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Docker overview

Creating a container

Loading and running a container

Saving a container

Slide 18 of 26

Page 19: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Loading and running a container

Host system: old GCC versionRun an interactive docker container

based on the image we created

Container: new GCC version

Attach a pseudo-shell to the container

Clean up when we’re done

Slide 19 of 26

Page 20: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Loading and running a container

Connect a second shell to the running container in another terminal window

List running containers

Slide 20 of 26

Page 21: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Docker overview

Creating a container

Loading and running a container

Saving a container

Slide 21 of 26

Page 22: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Saving a container

You can create a new image from any runningcontainer using docker commit

This creates a new image that contains all changes made in the container since it was started (and overwrites the existing image)

If you don't save, all changes are lost!

Slide 22 of 26

Page 23: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Saving a containerSlide 23 of 26

Page 24: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Saving a container

Images can be converted into tar files using

docker save

These tar files can be copied to other systems to run remote containers (using docker load)

Alternatively, you can publish your container in an online registry using docker push

Slide 24 of 26

Page 25: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

Summary

• Containers are a lightweight alternative for system emulation

• Easy to use

• Container images can be ported to other systems/hardware...

• EXTRA: container support in workflow management systems (see previous talk)

Slide 25 of 26

Page 26: An introduction to Docker · docker save These tar files can be copied to other systems to run remote containers (using docker load) Alternatively, you can publish your container

More information

A huge body of documentation can be found on https://docs.docker.com/

But the easiest way to learn Docker is using it!

Slide 26 of 26