Docker -- Build, Ship, Run An open platform for distributed applications for developers and sysadmins

#Installation

By default, the standard Docker Toolbox installation:

  • installs binaries for the Docker tools in /usr/local/bin
  • makes these binaries available to all users
  • updates any existing Virtual Box installation

#Docker Quickstart Terminal

Last login: Fri Jan  8 20:53:13 on console
bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
oscars-MacBook-Pro:~ xnpeng$ bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
Creating Machine default...
Creating CA: /Users/xnpeng/.docker/machine/certs/ca.pem
Creating client certificate: /Users/xnpeng/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(default) Copying /Users/xnpeng/.docker/machine/cache/boot2docker.iso to /Users/xnpeng/.docker/machine/machines/default/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting VM...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect Docker to this machine, run: /usr/local/bin/docker-machine env default
Setting environment variables for machine default...


                        ##          .
                  ##  ##  ##         ==
               ##  ##  ##  ##  ##     ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/


docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

image

#docker run hello-world

oscars-MacBook-Pro:~ xnpeng$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete
0a6ba66e537a: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/

#docker run -it ubuntu bash

 oscars-MacBook-Pro:~ xnpeng$ docker run -it ubuntu bash
 Unable to find image 'ubuntu:latest' locally
 latest: Pulling from library/ubuntu
 fcee8bcfe180: Pull complete
 4cdc0cbc1936: Pull complete
 d9e545b90db8: Pull complete
 c4bea91afef3: Pull complete
 Digest: sha256:b53bb7b0d18842214ac7472c2a8801e8682c247d30f1ba4bab0083a2e2e091ea
 Status: Downloaded newer image for ubuntu:latest
 root@c0c136c42ef7:/#

#docker folder

ls -l /usr/local/bin/dock*

oscars-MacBook-Pro:bin xnpeng$ ls -l doc*
-rwxr-xr-x  1 xnpeng  admin   9231840 Jan  5 00:33 docker
-rwxr-xr-x  1 xnpeng  admin   4938393 Jan  5 00:33 docker-compose
-rwxr-xr-x  1 xnpeng  admin  37948592 Jan  5 00:33 docker-machine

oscars-MacBook-Pro:bin xnpeng$ ls -l /usr/local/bin/dock*

-rwxr-xr-x  1 xnpeng  admin   9231840 Jan  5 00:33 /usr/local/bin/docker
-rwxr-xr-x  1 xnpeng  admin   4938393 Jan  5 00:33 /usr/local/bin/docker-compose
-rwxr-xr-x  1 xnpeng  admin  37948592 Jan  5 00:33 /usr/local/bin/docker-machine

#docker run docker/whalesay cowsay boo

oscars-MacBook-Pro:~ xnpeng$ docker run docker/whalesay cowsay boo
Unable to find image 'docker/whalesay:latest' locally
latest: Pulling from docker/whalesay

2880a3395ede: Pull complete
515565c29c94: Pull complete
98b15185dba7: Pull complete
2ce633e3e9c9: Pull complete
35217eff2e30: Pull complete
326bddfde6c0: Pull complete
3a2e7fe79da7: Pull complete
517de05c9075: Pull complete
8f17e9411cf6: Pull complete
ded5e192a685: Pull complete
Digest: sha256:178598e51a26abbc958b8a2e48825c90bc22e641de3d31e18aaf55f3258ba93b
Status: Downloaded newer image for docker/whalesay:latest
 _____
< boo >
 -----
    \
     \
      \
                    ##         .
              ##  ##  ##        ==
           ##  ##  ##  ##       ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/

#Build your own image

1 Write a Dockerfile

mkdir mydockerbuild
cd mydockerbuild

touch Dockerfile
subl Dockerfile

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay

2 Build a new image

oscars-MacBook-Pro:mydockerbuild xnpeng$ docker build -t docker-whale .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM docker/whalesay:latest
 ---> ded5e192a685
Step 2 : RUN apt-get -y update && apt-get install -y fortunes
 ---> Running in 130b6c0c07f5
Ign http://archive.ubuntu.com trusty InRelease
Get:1 http://archive.ubuntu.com trusty-updates InRelease [64.4 kB]
Get:2 http://archive.ubuntu.com trusty-security InRelease [64.4 kB]
Hit http://archive.ubuntu.com trusty Release.gpg
Get:3 http://archive.ubuntu.com trusty-updates/main Sources [311 kB]
Get:4 http://archive.ubuntu.com trusty-updates/restricted Sources [5219 B]
Get:5 http://archive.ubuntu.com trusty-updates/universe Sources [183 kB]
Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [857 kB]
Get:7 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [23.4 kB]
Get:8 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [432 kB]
Get:9 http://archive.ubuntu.com trusty-security/main Sources [129 kB]
Get:10 http://archive.ubuntu.com trusty-security/restricted Sources [3920 B]
Get:11 http://archive.ubuntu.com trusty-security/universe Sources [36.9 kB]
Get:12 http://archive.ubuntu.com trusty-security/main amd64 Packages [501 kB]
Get:13 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [20.2 kB]
Get:14 http://archive.ubuntu.com trusty-security/universe amd64 Packages [159 kB]
Hit http://archive.ubuntu.com trusty Release
Hit http://archive.ubuntu.com trusty/main Sources
Hit http://archive.ubuntu.com trusty/restricted Sources
Hit http://archive.ubuntu.com trusty/universe Sources
Hit http://archive.ubuntu.com trusty/main amd64 Packages
Hit http://archive.ubuntu.com trusty/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty/universe amd64 Packages
Fetched 2791 kB in 1min 7s (41.4 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  fortune-mod fortunes-min librecode0
Suggested packages:
  x11-utils bsdmainutils
The following NEW packages will be installed:
  fortune-mod fortunes fortunes-min librecode0
0 upgraded, 4 newly installed, 0 to remove and 60 not upgraded.
Need to get 1961 kB of archives.
After this operation, 4817 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main librecode0 amd64 3.6-21 [771 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/universe fortune-mod amd64 1:1.99.1-7 [39.5 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes-min all 1:1.99.1-7 [61.8 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes all 1:1.99.1-7 [1089 kB]
-    debconf: unable to initialize frontend: Dialog
-    debconf: (TERM is not set, so the dialog frontend is not usable.)
-    debconf: falling back to frontend: Readline
-    debconf: unable to initialize frontend: Readline
-    debconf: (This frontend requires a controlling tty.)
-    debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 1961 kB in 19s (102 kB/s)
Selecting previously unselected package librecode0:amd64.
(Reading database ... 13116 files and directories currently installed.)
Preparing to unpack .../librecode0_3.6-21_amd64.deb ...
Unpacking librecode0:amd64 (3.6-21) ...
Selecting previously unselected package fortune-mod.
Preparing to unpack .../fortune-mod_1%3a1.99.1-7_amd64.deb ...
Unpacking fortune-mod (1:1.99.1-7) ...
Selecting previously unselected package fortunes-min.
Preparing to unpack .../fortunes-min_1%3a1.99.1-7_all.deb ...
Unpacking fortunes-min (1:1.99.1-7) ...
Selecting previously unselected package fortunes.
Preparing to unpack .../fortunes_1%3a1.99.1-7_all.deb ...
Unpacking fortunes (1:1.99.1-7) ...
Setting up librecode0:amd64 (3.6-21) ...
Setting up fortune-mod (1:1.99.1-7) ...
Setting up fortunes-min (1:1.99.1-7) ...
Setting up fortunes (1:1.99.1-7) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
 ---> ef32c8496d3d
Removing intermediate container 130b6c0c07f5
Step 3 : CMD /usr/games/fortune -a | cowsay
 ---> Running in d915a96610e4
 ---> ab11941b8c0f
Removing intermediate container d915a96610e4
Successfully built ab11941b8c0f

#3 List images in local

docker images

the result:

oscars-MacBook-Pro:mydockerbuild xnpeng$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker-whale        latest              ab11941b8c0f        12 minutes ago      274.2 MB
ubuntu              latest              c4bea91afef3        3 days ago          187.9 MB
hello-world         latest              0a6ba66e537a        12 weeks ago        960 B
docker/whalesay     latest              ded5e192a685        7 months ago        247 MB

#4 Run the new image

docker run docker-whale

the result:

oscars-MacBook-Pro:mydockerbuild xnpeng$ docker run docker-whale
 _______________________________________
/ How wonderful opera would be if there \
\ were no singers.                      /
 ---------------------------------------
    \
     \
      \
                    ##         .
              ##  ##  ##        ==
           ##  ##  ##  ##       ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/
Written on January 8, 2016