11-1-2106
Docker is an open platform for building, shipping and running distributed applications.
docker.io
VM
Docker
http://docs.docker.com/installation
Docker Image:
A read-only template for creating containers. An image contains the installations of an application instance with its software and independence, and the process to run when the container is launched.
Docker container:
Created from an image and is the run time component of Docker. A container holds everything that is needed for an application instance to run, including an operating system, user-added files, meta-data, and the application instance dependencies.
from Docker Hub
Pulls per Day
Pulls per Second
Repositories on
Docker Hub
~ $ docker search -h
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
--automated=false Only show automated builds
--no-trunc=false Don't truncate output
-s, --stars=0 Only displays with at least x stars
~ $ docker search hello-world
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Docker... 24 [OK]
tutum/hello-world Image to test docker deployments. Has Apac... 12 [OK]
marcells/aspnet-hello-world ASP.NET vNext - Hello World 1 [OK]
vegasbrianc/docker-hello-world 1 [OK]
diegomarangoni/devops-hello-world-app Example application for deploying using Co... 1 [OK]
nirmata/hello-world 0 [OK]
crccheck/hello-world Hello World web server in under 2.5 MB 0 [OK]
poojathote/hello-world this is 3rd POC 0 [OK]
adamkdean/hello-world 0 [OK]
davelesser/hello-world 0 [OK]
milkyway/java-hello-world Java Hello World Test Docker Image 0 [OK]
rcarun/hello-world 0 [OK]
suryasumukh/hello-world A docker auto build test application 0 [OK]
sixeyed/coreclr-hello-world A simple Hello World sample, running as a ... 0 [OK]
keithchambers/docker-hello-world 0 [OK]
fermayo/hello-world 0 [OK]
craigbarrau/docker-java-hello-world This is an automated build of docker java-... 0 [OK]
svlapin/docker-hello-world Hello world automated build 0 [OK]
jaimalchohan/hello-world-node-docker A simple hello world app 0 [OK]
~ $ docker pull -h
Usage: docker pull [OPTIONS] NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]
Pull an image or a repository from the registry
-a, --all-tags=false Download all tagged images in the repository
--disable-content-trust=true Skip image verification
~ $ docker pull hello-world
latest: Pulling from hello-world
535020c3e8ad: Pull complete
af340544ed62: Pull complete
Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c
Status: Downloaded newer image for hello-world:latest
~ $
~ $ docker run -h
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
-a, --attach=[] Attach to STDIN, STDOUT or STDERR
--add-host=[] Add a custom host-to-IP mapping (host:ip)
--blkio-weight=0 Block IO weight (relative weight)
-c, --cpu-shares=0 CPU shares (relative weight)
[...]
~ $ docker run ubuntu:latest echo "Docker is awesome"
Unable to find images 'ubuntu:latest' locally
latest: Pulling from ubuntu
d3a1f33e8a5a: Pull complete
c22013c84729: Pull complete
d74508fb6632: Pull complete
91e54dfb1179: Pull complete
ubuntu:latest: The image you are pulling has been verified.
Digest: sha256:73fbe2308f5f5cb6e343425831b8ab44f10bbd77070ecdfbe4081daa4dbe3ed1
Status: Downloaded newer image for ubuntu:latest
Docker is awesome
~ $
~ $ docker run -it ubuntu:latest /bin/bash
root@b91b6d0cf193:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@b91b6d0cf193:/# exit
exit
~ $
~ $ docker run ubuntu:latest echo "Docker is awesome"
Unable to find images 'ubuntu:latest' locally
latest: Pulling from ubuntu
d3a1f33e8a5a: Pull complete
c22013c84729: Pull complete
d74508fb6632: Pull complete
91e54dfb1179: Pull complete
ubuntu:latest: The image you are pulling has been verified.
Digest: sha256:73fbe2308f5f5cb6e343425831b8ab44f10bbd77070ecdfbe4081daa4dbe3ed1
Status: Downloaded newer image for ubuntu:latest
Docker is awesome
~ $
~ $ docker images -h
Usage: docker images [OPTIONS] [REPOSITORY]
List images
-a, --all=false Show all images (default hides intermediate images)
--digests=false Show digests
-f, --filter=[] Filter output based on conditions provided
--help=false Print usage
--no-trunc=false Don't truncate output
-q, --quiet=false Only show numeric IDs
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 91e54dfb1179 16 minutes ago 188.4 MB
hello-world latest af340544ed62 4 minutes ago 960 B
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 91e54dfb1179 16 minutes ago 188.4 MB
hello-world latest af340544ed62 4 minutes ago 960 B
~ $ docker rmi -f hello-world
Untagged: hello-world:latest
Deleted: af340544ed62de0680f441c71fa1a80cb084678fed42bae393e543faea3a572c
Deleted: 535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 91e54dfb1179 16 minutes ago 188.4 MB
~ $ docker ps -h
Usage: docker ps [OPTIONS]
List containers
-a, --all=false Show all containers (default shows just running)
--before="" Show only container created before Id or Name
-f, --filter=[] Filter output based on conditions provided
-l, --latest=false Show the latest created container, include non-running
-n=-1 Show n last created containers, include non-running
--no-trunc=false Don't truncate output
-q, --quiet=false Only display numeric IDs
-s, --size=false Display total file sizes
--since="" Show created since Id or Name, include non-running
--format=[] Pretty-print containers using a Go template
~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89951e446cf0 postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp pensive
dd5fe50ab712 ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds adoring
eea75a0a071f ubuntu:latest "/bin/bash" About a minute ago Up About a minute insane
~ $
~ $ docker rm -f 89951e446cf0
89951e446cf0
~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd5fe50ab712 ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds adoring
eea75a0a071f ubuntu:latest "/bin/bash" About a minute ago Up About a minute insane
~ $
~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89951e446cf0 postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp pensive
dd5fe50ab712 ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds adoring
eea75a0a071f ubuntu:latest "/bin/bash" About a minute ago Up About a minute insane
~ $
~ $ docker exec -h
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
-d, --detach=false Detached mode: run command in the background
-i, --interactive=false Keep STDIN open even if not attached
-t, --tty=false Allocate a pseudo-TTY
-u, --user= Username or UID (format: <name|uid>[:<group|gid>])
~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89951e446cf0 postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp pensive
dd5fe50ab712 ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds adoring
eea75a0a071f ubuntu:latest "/bin/bash" About a minute ago Up About a minute insane
~ $
~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89951e446cf0 postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp pensive
dd5fe50ab712 ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds adoring
eea75a0a071f ubuntu:latest "/bin/bash" About a minute ago Up About a minute insane
~ $
~ $ docker exec -it dd5fe50ab712 /bin/bash
root@dd5fe50ab712:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@dd5fe50ab712:/# exit
exit
~ $
A data volume is a specially-designated directory within one or more containers that bypasses the Union File System.
~ $ ls /Users/baptou/myDirectory
file1 file2 file3
~ $ docker run -it -v /Users/baptou/myDirectory:/opt ubuntu:latest /bin/bash
root@29088b02f260:/# ls /opt
file1 file2 file3
root@29088b02f260:/# rm /opt/file2
root@29088b02f260:/# ls /opt
file1 file3
root@29088b02f260:/# exit
exit
~ $ ls /Users/baptou/myDirectory
file1 file3
~ $
~ $ docker commit -h
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
-a, --author="" Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change=[] Apply specified Dockerfile instructions while committing the image
-m, --message="" Commit message
-p, --pause=true Pause container during commit
~ $ docker run -d ubuntu /bin/bash -c "apt-get install -y hello"
009e8061df58b8b123ee
~ $ docker commit -m "My first container with a Commit" 009e8061df58b8b123ee baptou/hello
b88f9422f14dc055427d39bf6971f8415511fdaa3182a37869c14c4893664c43
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
baptwaels/hello latest b88f9422f14d 7 seconds ago 189.3 MB
feedbackfront latest 34cd8b4a3d8b 4 weeks ago 163 MB
offer/feedbackfront latest 63a5a64ddc7a 4 weeks ago 163 MB
offer/feedback-front latest 63a5a64ddc7a 4 weeks ago 163 MB
~ $ docker run baptwaels/hello
Reading package lists...
Building dependency tree...
Reading state information...
hello is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
~ $ docker run -it baptwaels/hello /bin/bash
root@df8d31633a9a:/# hello
Hello, world!
root@df8d31633a9a:/# exit
exit
~ $
~ $ docker push -h
Usage: docker push NAME[:TAG]
Push an image or a repository to the registry
--disable-content-trust=true Skip image signing
~ $ docker push baptwaels/hello
The push refers to a repository [baptwaels/hello] (len: 1)
b88f9422f14d: Image push failed
Please login prior to push:
Username: baptwaels
Password:
Email: bwaels@gmail.com
WARNING: login credentials saved in /Users/baptou/.dockercfg.
Login Succeeded
The push refers to a repository [baptwaels/hello] (len: 1)
b88f9422f14d: Image already exists
91e54dfb1179: Image successfully pushed
d74508fb6632: Image successfully pushed
c22013c84729: Image successfully pushed
d3a1f33e8a5a: Image successfully pushed
Digest: sha256:d659f9011eab6d04b3d9fd9f6324e23505bd1299c52d295c4b04ebe3e58878ce
~ $
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
FROM ubuntu:latest
RUN apt-get install hello -y
RUN apt-get install vim -y
Dockerfile
FROM ubuntu:latest
RUN apt-get install hello -y
RUN apt-get install vim -y
Dockerfile
~ $ docker build -t myubuntu .
~ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
myubuntu latest 4b205af179df 5 seconds ago 188.9 MB
Shell
The idea behind is awesome
The community behind is awesome
Can we use it in production?