0% found this document useful (0 votes)
73 views24 pages

Docker

The document provides an overview of Docker, explaining that it allows for the creation of independent and isolated environments for application deployment. It compares Docker to virtual environments (venv) and virtual machines (VM), noting that Docker isolates all dependencies but uses parts of the host OS, making it faster and lighter than a VM. Key Docker objects like containers and images are described, with containers being run instances of images. The document then offers guidance on how to work with Docker, covering starting containers, managing data volumes, using Jupyter notebooks, and version control via commits and pulls of images.

Uploaded by

Liza Kozlova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views24 pages

Docker

The document provides an overview of Docker, explaining that it allows for the creation of independent and isolated environments for application deployment. It compares Docker to virtual environments (venv) and virtual machines (VM), noting that Docker isolates all dependencies but uses parts of the host OS, making it faster and lighter than a VM. Key Docker objects like containers and images are described, with containers being run instances of images. The document then offers guidance on how to work with Docker, covering starting containers, managing data volumes, using Jupyter notebooks, and version control via commits and pulls of images.

Uploaded by

Liza Kozlova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Docker

for dummies

Elizaveta Kozlova
Plan
First questions I had

• What is docker and why people use it?

• How to manage data?

• How to work with jupyter notebooks?

• What to do when you want to change the image?


What is it?

independent and isolated


environments for app
deployment
What is it?

venv VM docker

What’s the difference?


What is it?

venv VM docker

source: https://stephen-odaibo.medium.com/docker-containers-python-virtual-environments-virtual-machines-d00aa9b8475
What is it?

venv VM docker

source: https://stephen-odaibo.medium.com/docker-containers-python-virtual-environments-virtual-machines-d00aa9b8475
What is it?

venv VM docker

source: https://stephen-odaibo.medium.com/docker-containers-python-virtual-environments-virtual-machines-d00aa9b8475
What is it?

venv VM docker

isolates all
only isolates
dependencies, but
python
uses deeper parts of
host OS 

creates a whole (so it must be linux)
isolated OS
What is it?

venv VM docker

isolates all
only isolates
dependencies, but
python
uses deeper parts of
host OS 

creates a whole (so it must be linux)
isolated OS

fast, light, sufficient to completely avoid dependency problems


What is it?
Objects

container

read-write layer
image

read-only template
What is it?
Objects

container

create from Dockerfile 
 ADD code.py


or an existing container

or pull from dockerhub
RUN pip install numpy
layered

(most changeable layers 

added last)
FROM ubuntu
What is it?
Objects

container

create from Dockerfile 
 WORKDIR


ADD code.py
/home
or an existing container

or pull from dockerhub
RUN pip install numpy
layered

(layers most likely to be changed

added last)
FROM ubuntu

version control
How to work with it?
Start
1. create a Dockerfile (in any text editor)

2. build an image 

$ docker build -t image_name .

3. create a container

$ docker run -it --name=container_name
image_name

(image_name can be pulled from dockerhub;

--rm option will clean up the container when you exit)

4. do stuff as usual

5. to reconnect:

$ docker attach container_name
How to work with it?
Data

by default a container is completely isolated: 



it can’t access data from the host or save anything

solution: data volumes

$ docker run -it -v /host_path:/container_path


image_name

paths need to be absolute!


How to work with it?
Data

by default a container is completely isolated: 



it can’t access data from the host or save anything

solution: data volumes

$ docker run -it -v host_path:/container_path 



image_name

now a volume named host_path was created 



(no connection to the host system, but can be attached to another
container)
How to work with it?
Data

by default a container is completely isolated: 



it can’t access data from the host or save anything

solution: data volumes

$ docker run -it -v /host_path:/container_path 



-v /host_path2:/container_path2 image_name

the option can be used multiple times


How to work with it?
Jupyter

Jupyter docker stacks:



https://jupyter-docker-stacks.readthedocs.io/en/latest/

ready-to-run

options with different libraries pre-installed


How to work with it?
Jupyter

most basic Dockerfile

$ FROM python:latest
$ RUN pip3 install jupyter

more complex alternative: 



https://u.group/thinking/how-to-put-jupyter-notebooks-in-a-dockerfile/

How to work with it?


Jupyter
local machine:

$ ssh -L <host port>:localhost:<remote port> 



user@remote

server:
$ docker run -it -p <remote port>:<container port> 

--name <container name>

container:
$ jupyter notebook --ip 0.0.0.0 --port 

<container port> --allow-root
How to work with it?
Jupyter

second most basic Dockerfile

$ FROM python:latest
$ RUN pip3 install jupyter
$ CMD ["jupyter notebook", "—ip=0.0.0.0",
"--port=<container port>", «-—allow-root"]

this way a remote notebook starts automatically


How to work with it?
Jupyter

jupyter_base:

(an image I saved on the server)

second most basic Dockerfile

+ git

+ numpy, scipy, matplotlib, sklearn

+ pytorch (latest), tensorflow (latest)


How to work with it?
Jupyter (my example)

to start a new (detached) container from jupyter_base:


$ nvidia-docker run --name=jupyter -it -p 8889:8889
-v ~/test/data:/home -w /home -d jupyter_base

to connect to the terminal of that container:


$ docker exec -it jupyter bash (to quit press Ctrl+p, Ctrl+q)

to attach to the notebook:


$ docker attach -it jupyter (to quit print exit)
How to work with it?
Version control

some commands similar to git

$ docker commit container_name image_name

$ docker pull image_name


(tags are usually used to denote versions:

image_name:tag)
$ docker push image_name

+ .dockerignore for build


How to work with it?
Random useful things

use nvidia-docker if you are planning to use GPU 



(commands are the same)

if something is running in the container when you commit, it is paused 



(there is an option to not do that, but data might get corrupted)

list all containers: $ docker ps -a


list all images: $ docker images

detach from a running container: Ctrl + p; Ctrl + q

You might also like