From charlesreid1

Revision as of 03:27, 24 March 2017 by Admin (talk | contribs) (→‎Volumes)

Navigating

Filesystem basics

Working directory

You can set the working directory using the -w flag:

$ docker  run -w /path/to/dir/ -i -t  ubuntu pwd

Volumes

You can set storage drive options using storage opt fllag:

$ docker run -it --storage-opt size=120G fedora /bin/bash

You can also mount external (your machine) drives/folders inside the Docker container:

$ docker  run  \
  -v `pwd`:`pwd` \
  -w `pwd` \
  -i -t  ubuntu pwd


The -v flag mounts the current working directory into the container. The -w lets the command being executed inside the current working directory, by changing into the directory to the value returned by pwd. So this combination executes the command using the container, but inside the current working directory.

Docker run documentation


Docker creates any folders on your machine if they don't exist, before it spins up the docker container:

$ docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash

Read only control can be set on volumes as well: --read-only flag.

$ docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v /path/to/static-docker-binary:/usr/bin/docker busybox sh


The --read-only flag mounts the container’s root filesystem as read only prohibiting writes to locations other than the specified volumes for the container.

Docker run documentation