Privacy Policy
Snippets index

  Docker notes


OBSOLETE! see https://github.com/morlandi/DockerDev

Cheatsheet

docker container ls -a List all containers
docker container ls -a -q List all containers in "quiet" mode
docker rm $(docker container ls -a -q) Remove all containsers
docker image ls -a List images
docker rmi IMAGENAME Remove image

Running an instantaneous Ubuntu Machine

System Message: WARNING/2 (<string>, line 23)

Title underline too short.

Running an instantaneous Ubuntu Machine
--------------------------------------

We will run a Ubuntu machine working with an interactive docker container.

This is the very ground level knowledge on how using Docker as a user environment, rather than a standalone container with an app running in it.

docker run --interactive --tty ubuntu /bin/bash

What we did:

  • we created a ubuntu machine with a random name

or:

docker run --name ubuntu -v /Users/morlandi/tmp/sources:/src -t -i ubuntu /bin/bash

What we did:

  • we created a ubuntu machine named "ubuntu"
  • with a volumes attached to it, directly from our machine
  • we mapped the volume using the "-v" flag [local]:[destination],

The lifetime of a container is the life time of its single main process.

Time to check docker, see what happened with it:

docker ps -a

CONTAINER ID        IMAGE               COMMAND             NAMES
e41423f7856b        ubuntu              "/bin/bash"         ubuntu
ed5887209364        ubuntu              "/bin/bash"         cool_proskuriakova

Finally, we cleanup the images:

docker rm -f cool_proskuriakova
docker rm -f ubuntu

Mac docker volume mount using osxfs

Docker Desktop for Mac started using osxfs for supporting volume mounting on MacOS.

The following command mounts the ~/Desktop directory to the docker container:

docker run -it -v ~/Desktop:/Desktop ubuntu bash

Proof:

from the container:

root@71f6e65abc6e:/# ls /
bin  boot  Desktop  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@71f6e65abc6e:/# ls -l /Desktop/

    -rw-r--r-- 1 root root 127138 Jul 17 14:52 '/Desktop/Screenshot 2020-07-17 at 16.51.58.png'
    -rw-r--r-- 1 root root 648435 Jul 17 15:47 '/Desktop/Screenshot 2020-07-17 at 17.47.21.png'
    -rw-r--r-- 1 root root 249486 Jul 17 16:15 '/Desktop/Screenshot 2020-07-17 at 18.15.15.png'
    -rw-r--r-- 1 root root 821404 Jul 18 08:57 '/Desktop/Screenshot 2020-07-18 at 10.57.38.png'

from the host:

$ ls -l ~/Desktop

    -rw-r--r--@ 1 morlandi  staff  127138 Jul 17 16:52 Desktop/Screenshot 2020-07-17 at 16.51.58.png
    -rw-r--r--@ 1 morlandi  staff  648435 Jul 17 17:47 Desktop/Screenshot 2020-07-17 at 17.47.21.png
    -rw-r--r--@ 1 morlandi  staff  249486 Jul 17 18:15 Desktop/Screenshot 2020-07-17 at 18.15.15.png
    -rw-r--r--@ 1 morlandi  staff  821404 Jul 18 10:57 Desktop/Screenshot 2020-07-18 at 10.57.38.png