Getting started with Docker

Drew Sears edited this page Feb 28, 2017 · 1 revision

Notes from reading https://docs.docker.com/engine/getstarted/

Installation

On Ubuntu, run the install script:

curl -fsSL https://get.docker.com/ | sh

Test your installation:

$ sudo docker run hello-world
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 ID:
 https://cloud.docker.com/

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

Show all running containers:

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
1557c8607acf        hello-world         "/hello"            9 seconds ago       Exited (0) 8 seconds ago                       mystifying_kare

Images and containers

An image is a static, stateless filesystem plus configuration metadata.

A container is a running instance of an image.

Run the whalesay image

$ docker run docker/whalesay cowsay boo-boo
Unable to find image 'docker/whalesay:latest' locally
latest: Pulling from docker/whalesay
e190868d63f8: Pull complete 
909cd34c6fd7: Pull complete 
0b9bfabab7c1: Pull complete 
a3ed95caeb02: Pull complete 
00bf65475aba: Pull complete 
c57b6bcc83e3: Pull complete 
8978f6879e2f: Pull complete 
8eed3712d2cf: Pull complete 
Digest: sha256:178598e51a26abbc958b8a2e48825c90bc22e641de3d31e18aaf55f3258ba93b
Status: Downloaded newer image for docker/whalesay:latest
 _________ 
< boo-boo >
 --------- 
    \
     \
      \     
                    ##        .            
              ## ## ##       ==            
           ## ## ## ##      ===            
       /""""""""""""""""___/ ===        
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~   
       \______ o          __/            
        \    \        __/             
          \____\______/   

Make your own image

Start a build directory and edit a Dockerfile:

$ mkdir mydockerbuild
$ cd mydockerbuild
$ nano Dockerfile

Dockerfile contents:

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

Build docker-whale:

$ docker build -t docker-whale .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM docker/whalesay:latest
 ---> 6b362a9f73eb
Step 2/3 : RUN apt-get -y update && apt-get install -y fortunes
 ---> Running in 84d1bfe30fff
...
 ---> b20bfda165ef
Removing intermediate container 84d1bfe30fff
Step 3/3 : CMD /usr/games/fortune -a | cowsay
 ---> Running in 49ed9ee472ac
 ---> 23ee15a2facd
Removing intermediate container 49ed9ee472ac
Successfully built 23ee15a2facd

Run docker-whale:

$ docker run docker-whale
 _________________________________________ 
/ DOS: n., A small annoying boot virus    \
| that causes random spontaneous system   |
|                                         |
| crashes, usually just before saving a   |
| massive project. Easily cured by        |
|                                         |
| UNIX. See also MS-DOS, IBM-DOS, DR-DOS. |
|                                         |
\ -- David Vicker's .plan                 /
 ----------------------------------------- 
    \
     \
      \     
                    ##        .            
              ## ## ##       ==            
           ## ## ## ##      ===            
       /""""""""""""""""___/ ===        
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~   
       \______ o          __/            
        \    \        __/             
          \____\______/   

Where to go next

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.