Docker/Volumes: Difference between revisions
From charlesreid1
| Line 34: | Line 34: | ||
This starts a docker container with the name "pwd", and mounts the current working directory (say, <code>/home/someone/docker</code>) to the same path in the docker image <code>/home/someone/docker</code>. It then sets the working directory to that directory. | This starts a docker container with the name "pwd", and mounts the current working directory (say, <code>/home/someone/docker</code>) to the same path in the docker image <code>/home/someone/docker</code>. It then sets the working directory to that directory. | ||
== | ==Making Container Filesystem Read-Only== | ||
Read only control can be set on volumes as well: <code>--read-only</code> flag. This flag makes the entire contents of the container's root filesystem read-only, except for volumes mounted with the <code>-v</code> flag. To illustrate: | Read only control can be set on volumes as well: <code>--read-only</code> flag. This flag makes the entire contents of the container's root filesystem read-only, except for volumes mounted with the <code>-v</code> flag. To illustrate: | ||
| Line 47: | Line 47: | ||
$ # no error, no poblem! | $ # no error, no poblem! | ||
</pre> | |||
==Making Host Directories Read-Only== | |||
To mount a host directory on the container's filesystem, you can use the <code>-v</code> flag. To mount a host directory as read-only on the container's filesystem, add <code>:ro</code> to the end of the flag: | |||
<pre> | |||
$ docker run -v <host path>:/<container path>:ro ... | |||
</pre> | |||
For example: | |||
<pre> | |||
$ docker run -v /home/someone/scripts:/scripts:ro -it ubuntu | |||
root@a53d902e433b:/# | |||
root@a53d902e433b:/# touch /scripts/file | |||
touch: cannot touch '/scripts/file': Read-only file system | |||
</pre> | </pre> | ||
Revision as of 03:21, 25 March 2017
Basics
Working Directory
First, we can set the working directory when we run a container by using the -w flag:
$ docker run -w /path/to/dir/ -i -t ubuntu pwd
This starts a new ubuntu image called pwd with the current working directory (when it starts up) set to /path/to/dir.
Setting Disk Space
We can set the amount of storage for the docker container using --storage-opt flag:
$ docker run -it --storage-opt size=120G fedora /bin/bash
This starts a fedora image with a bash shell, and uses 120 gb for the container.
Mounting Host Folders
Can mount folders on the host machine to drives in the docker machine:
$ docker run \ -v `pwd`:`pwd` \ -w `pwd` \ -i -t ubuntu pwd
This starts a docker container with the name "pwd", and mounts the current working directory (say, /home/someone/docker) to the same path in the docker image /home/someone/docker. It then sets the working directory to that directory.
Making Container Filesystem Read-Only
Read only control can be set on volumes as well: --read-only flag. This flag makes the entire contents of the container's root filesystem read-only, except for volumes mounted with the -v flag. To illustrate:
$ # this will not work, because /canttouchthis is part of the container's root filesystem $ docker run -t --read-only -v /icanwrite busybox touch /canttouchthis touch: /canttouchthis: Read-only file system $ # this will work, because /icanwrite is mounted with -v and is not read-only $ docker run --read-only -v /icanwrite busybox touch /icanwrite/here $ # no error, no poblem!
Making Host Directories Read-Only
To mount a host directory on the container's filesystem, you can use the -v flag. To mount a host directory as read-only on the container's filesystem, add :ro to the end of the flag:
$ docker run -v <host path>:/<container path>:ro ...
For example:
$ docker run -v /home/someone/scripts:/scripts:ro -it ubuntu root@a53d902e433b:/# root@a53d902e433b:/# touch /scripts/file touch: cannot touch '/scripts/file': Read-only file system
Patterns
This section covers some patterns for organizing files so that you can move things in and out from containers, while also keeping in line with the philosophy behind docker containers, which is that they should be stateless.
A data volume is a specially-designated directory within one or more containers that bypasses the Union File System to provide several useful features for persistent or shared data:
- Data volumes can be shared and reused between containers
- Changes to a data volume are made directly
- Changes to a data volume will not be included when you update an image
Flags
| docker notes on the virtual microservice container platform
Installing the docker platform: Docker/Installing Docker Hello World: Docker/Hello World
Creating Docker Containers: Getting docker containers from docker hub: Docker/Dockerhub Creating docker containers with dockerfiles: Docker/Dockerfiles Managing Dockerfiles using git: Docker/Dockerfiles/Git Setting up Python virtualenv in container: Docker/Virtualenv
Running docker containers: Docker/Basics Dealing with volumes in Docker images: Docker/Volumes Removing Docker images: Docker/Removing Images Rsync Docker Container: Docker/Rsync
Networking with Docker Containers:
|
| docker pods pods are groups of docker containers that travel together
Docker pods are collections of Docker containers that are intended to run in concert for various applications.
Wireless Sensor Data Acquisition Pod The wireless sensor data acquisition pod deploys containers This pod uses the following technologies: Stunnel · Rsync · Apache · MongoDB · Python · Jupyter (numerical Python stack)
Deep Learning Pod This pod utilizes the following technologies: Python · Sklearn · Jupyter (numerical Python stack) · Keras · TensorFlow
|