latest docker version on centos-7

                       Learning the Basics of Docker

#################
Docker Installation
#################

[mohammedrafi@docker ~]$ sudo yum update -y

[mohammedrafi@docker ~]$ uname -a
Linux docker 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[mohammedrafi@docker ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

[mohammedrafi@docker ~]$ sudo yum install -y yum-utils

[mohammedrafi@docker ~]$ sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo

[mohammedrafi@docker ~]$ sudo yum makecache fast

[mohammedrafi@docker ~]$ sudo yum install docker-ce -y
[mohammedrafi@docker ~]$ sudo systemctl start docker

[mohammedrafi@docker ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[mohammedrafi@docker ~]$ systemctl status docker
● docker.service – Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2017-05-05 12:42:36 UTC; 10s ago
Docs: https://docs.docker.com
Main PID: 10096 (dockerd)
Memory: 15.3M
CGroup: /system.slice/docker.service
├─10096 /usr/bin/dockerd
└─10099 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock –metrics-interval=0 –start-timeout 2m -…

May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.195729672Z” level=warning msg=”overlay: the backing xfs filesystem is format…
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.253887118Z” level=info msg=”Graph migration to content-addressabilit…seconds”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.255194805Z” level=info msg=”Loading containers: start.”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.305471124Z” level=info msg=”Firewalld running: true”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.753756414Z” level=info msg=”Default bridge (docker0) is assigned wit…address”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.939189996Z” level=info msg=”Loading containers: done.”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.947429958Z” level=info msg=”Daemon has completed initialization”
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.947454568Z” level=info msg=”Docker daemon” commit=c6d412e graphdrive….03.1-ce
May 05 12:42:36 docker dockerd[10096]: time=”2017-05-05T12:42:36.967696842Z” level=info msg=”API listen on /var/run/docker.sock”
May 05 12:42:36 docker systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

[mohammedrafi@docker ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP qlen 1000
link/ether 42:01:0a:80:00:02 brd ff:ff:ff:ff:ff:ff
inet 10.128.0.2/32 brd 10.128.0.2 scope global dynamic eth0
valid_lft 85098sec preferred_lft 85098sec
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:d8:c3:16:bb brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[mohammedrafi@docker ~]$ sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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 ID:
https://cloud.docker.com/

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

mohammedrafi@docker ~]$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/images/json: dial unix /var/run/docker.sock: connect: permission denied
[mohammedrafi@docker ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 3 months ago 1.84 kB

[mohammedrafi@docker ~]$ sudo grep docker /etc/group
docker:x:994:

[mohammedrafi@docker ~]$ ls -l /var/run/docker.sock
srw-rw—-. 1 root docker 0 May 5 12:42 /var/run/docker.sock

[mohammedrafi@docker ~]$ sudo usermod -aG docker $(whoami)

[mohammedrafi@docker ~]$ sudo grep docker /etc/group
docker:x:994:mohammedrafi

[mohammedrafi@docker ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 3 months ago 1.84 kB

[mohammedrafi@docker ~]$ docker

Usage: docker COMMAND

A self-sufficient runtime for containers

Options:
–config string Location of client config files (default “/home/mohammedrafi/.docker”)
-D, –debug Enable debug mode
–help Print usage
-H, –host list Daemon socket(s) to connect to (default [])
-l, –log-level string Set the logging level (“debug”, “info”, “warn”, “error”, “fatal”) (default “info”)
–tls Use TLS; implied by –tlsverify
–tlscacert string Trust certs signed only by this CA (default “/home/mohammedrafi/.docker/ca.pem”)
–tlscert string Path to TLS certificate file (default “/home/mohammedrafi/.docker/cert.pem”)
–tlskey string Path to TLS key file (default “/home/mohammedrafi/.docker/key.pem”)
–tlsverify Use TLS and verify the remote
-v, –version Print version information and quit

Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes

Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container’s changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container’s filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container’s filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Run ‘docker COMMAND –help’ for more information on a command.

[mohammedrafi@docker ~]$ docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:05:44 2017
OS/Arch: linux/amd64

Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:05:44 2017
OS/Arch: linux/amd64
Experimental: false

[mohammedrafi@docker ~]$ docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.03.1-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.16.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.613 GiB
Name: docker
ID: F4RW:YUOK:CLJX:O6FN:KOLP:CSWY:2F6T:OQEV:VG56:R52M:PA56:B7XI
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

[mohammedrafi@docker ~]$ sudo ls -l /var/lib/docker/
total 4
drwx——. 3 root root 77 May 5 12:44 containers
drwx——. 3 root root 20 May 5 12:42 image
drwxr-x—. 3 root root 18 May 5 12:42 network
drwx——. 5 root root 4096 May 5 12:44 overlay
drwx——. 4 root root 30 May 5 12:42 plugins
drwx——. 2 root root 6 May 5 12:42 swarm
drwx——. 2 root root 6 May 5 12:44 tmp
drwx——. 2 root root 6 May 5 12:42 trust
drwx——. 2 root root 24 May 5 12:42 volumes

[mohammedrafi@docker ~]$ sudo ls -l /var/lib/docker/containers
total 4
drwx——. 4 root root 4096 May 5 12:44 72fae712502dd211aabd5ffdb79cb107810162ae5bb91275cfba641080276f41

[mohammedrafi@docker ~]$ sudo ls -l /var/lib/docker/containers/72fae712502dd211aabd5ffdb79cb107810162ae5bb91275cfba641080276f41
total 28
-rw-r—–. 1 root root 2273 May 5 12:44 72fae712502dd211aabd5ffdb79cb107810162ae5bb91275cfba641080276f41-json.log
drwx——. 2 root root 6 May 5 12:44 checkpoints
-rw-r–r–. 1 root root 2460 May 5 12:44 config.v2.json
-rw-r–r–. 1 root root 1117 May 5 12:44 hostconfig.json
-rw-r–r–. 1 root root 13 May 5 12:44 hostname
-rw-r–r–. 1 root root 174 May 5 12:44 hosts
-rw-r–r–. 1 root root 114 May 5 12:44 resolv.conf
-rw-r–r–. 1 root root 71 May 5 12:44 resolv.conf.hash
drwx——. 2 root root 6 May 5 12:44 shm

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
72fae712502d hello-world “/hello” 14 minutes ago Exited (0) 14 minutes ago elegant_lumiere

[root@docker ~]# ls -l /var/lib/docker/image/overlay/imagedb/content/sha256/
total 4
-rw——-. 1 root root 1478 May 5 12:44 48b5124b2768d2b917edcb640435044a97967015485e812545546cbed5cf0233
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 3 months ago 1.84 kB

[root@docker ~]# ls -lR /var/lib/docker/

#################
Creating Our First Image
#################

[mohammedrafi@docker ~]$ docker pull ubuntu:xenial
xenial: Pulling from library/ubuntu
aafe6b5e13de: Pull complete
0a2b43a72660: Pull complete
18bdd1e546d2: Pull complete
8198342c3e05: Pull complete
f56970a44fd4: Pull complete
Digest: sha256:f3a61450ae43896c4332bda5e78b453f4a93179045f20c8181043b26b5e79028
Status: Downloaded newer image for ubuntu:xenial

[mohammedrafi@docker ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu xenial f7b3f317ec73 10 days ago 117 MB
hello-world latest 48b5124b2768 3 months ago 1.84 kB

[mohammedrafi@docker ~]$ docker run -it ubuntu:xenial
root@1c62173e85b5:/#

root@1c62173e85b5:/# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 18232 1928 ? Ss 13:12 0:00 /bin/bash
root 9 0.0 0.0 34416 1456 ? R+ 13:13 0:00 ps aux

[root@1c62173e85b5:/# exit
[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c62173e85b5 ubuntu:xenial “/bin/bash” 3 minutes ago Exited (0) 13 seconds ago modest_wilson
72fae712502d hello-world “/hello” 32 minutes ago Exited (0) 32 minutes ago elegant_lumiere

[mohammedrafi@docker ~]$ docker restart modest_wilson
modest_wilson

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c62173e85b5 ubuntu:xenial “/bin/bash” 4 minutes ago Up 3 seconds modest_wilson

[mohammedrafi@docker ~]$ docker inspect modest_wilson
[
{
“Id”: “1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252”,
“Created”: “2017-05-05T13:12:59.061933744Z”,
“Path”: “/bin/bash”,
“Args”: [],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 10740,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2017-05-05T13:17:37.603916304Z”,
“FinishedAt”: “2017-05-05T13:16:37.702619672Z”
},
“Image”: “sha256:f7b3f317ec734a73deca91b34c2b1e3dd7454650da9c8ef3047d29a873865178”,
“ResolvConfPath”: “/var/lib/docker/containers/1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252/hostname”,
“HostsPath”: “/var/lib/docker/containers/1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252/hosts”,
“LogPath”: “/var/lib/docker/containers/1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252/1c62173e85b55d443f13699eeac0533a59f1ade000ce000252d62cdced368252-json.log”,
“Name”: “/modest_wilson”,
“RestartCount”: 0,
“Driver”: “overlay”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: -1,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Name”: “overlay”,
“Data”: {
“LowerDir”: “/var/lib/docker/overlay/b25a0d8276ae04d90dca031449ae025141e7c7f1afa2624bdd9cd0ba46d9bdc9/root”,
“MergedDir”: “/var/lib/docker/overlay/f127c9e7056ca2bc97e99d9b7aeffc0308379b8977a329dbdfc87b40b26c772a/merged”,
“UpperDir”: “/var/lib/docker/overlay/f127c9e7056ca2bc97e99d9b7aeffc0308379b8977a329dbdfc87b40b26c772a/upper”,
“WorkDir”: “/var/lib/docker/overlay/f127c9e7056ca2bc97e99d9b7aeffc0308379b8977a329dbdfc87b40b26c772a/work”
}
},
“Mounts”: [],
“Config”: {
“Hostname”: “1c62173e85b5”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: true,
“AttachStdout”: true,
“AttachStderr”: true,
“Tty”: true,
“OpenStdin”: true,
“StdinOnce”: true,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/bash”
],
“ArgsEscaped”: true,
“Image”: “ubuntu:xenial”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “f6d479a35f082cc5dc6aa665a6fbfedab82ca2a626c6de4f30e9e9ffd921f5d5”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {},
“SandboxKey”: “/var/run/docker/netns/f6d479a35f08”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “978aa885be80d9c5669eaa81cde5157db28fcfc7b7c1492be2c173db98c38211”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “164df530e6942fade5210d39c80b6694e0fdc8bc7192c67bf050e64df2f0d241”,
“EndpointID”: “978aa885be80d9c5669eaa81cde5157db28fcfc7b7c1492be2c173db98c38211”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”
}
}
}
}
]

[mohammedrafi@docker ~]$ docker attach modest_wilson
root@1c62173e85b5:/#

root@1c62173e85b5:/# exit

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

#################
Working with Multiple images
#################

[mohammedrafi@docker ~]$ docker run -itd ubuntu:xenial /bin/bash
77eec9adb89cba5b721285bf6184bc3f7a0d8bc5f71ade5998a9f8216dfde31e

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77eec9adb89c ubuntu:xenial “/bin/bash” 29 seconds ago Up 28 seconds elegant_boyd

[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77eec9adb89c ubuntu:xenial “/bin/bash” 4 minutes ago Up 4 minutes elegant_boyd
1c62173e85b5 ubuntu:xenial “/bin/bash” 6 hours ago Exited (0) 5 hours ago modest_wilson
72fae712502d hello-world “/hello” 6 hours ago Exited (0) 6 hours ago elegant_lumiere

[mohammedrafi@docker ~]$ docker attach elegant_boyd
root@77eec9adb89c:/#

root@77eec9adb89c:/# exit

[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77eec9adb89c ubuntu:xenial “/bin/bash” 5 minutes ago Exited (0) 3 seconds ago elegant_boyd
1c62173e85b5 ubuntu:xenial “/bin/bash” 6 hours ago Exited (0) 6 hours ago modest_wilson
72fae712502d hello-world “/hello” 6 hours ago Exited (0) 6 hours ago elegant_lumiere

[mohammedrafi@docker ~]$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 5943 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker c… 1014 [OK]

mohammedrafi@docker ~]$ docker pull ruby
Using default tag: latest
latest: Pulling from library/ruby
cd0a524342ef: Pull complete
e39c3ffe4133: Pull complete
85334a7c2001: Pull complete
4c546d9d6a84: Pull complete
dd2ea17fcd18: Pull complete
2435260ee93b: Pull complete
11ac7620c19d: Pull complete
a4d3eea32933: Pull complete
Digest: sha256:6b8c363e222d688b8b3b3a0543afe8b47c343e3ae21e17a139a4664792a6c495
Status: Downloaded newer image for ruby:latest

[mohammedrafi@docker ~]$ docker run -it ruby /bin/bash
root@a303daf3625d:/#

root@a303daf3625d:/# irb
irb(main):001:0>
root@a303daf3625d:/# gem
RubyGems is a sophisticated package manager for Ruby. This is a
basic help message containing pointers to more information.

Usage:
gem -h/–help
gem -v/–version
gem command [arguments…] [options…]

Examples:
gem install rake
gem list –local
gem build package.gemspec
gem help install

Further help:
gem help commands list all ‘gem’ commands
gem help examples show some examples of usage
gem help gem_dependencies gem dependencies file guide
gem help platforms gem platforms guide
gem help show help on COMMAND
(e.g. ‘gem help install’)
gem server present a web page at
http://localhost:8808/
with info about installed gems
Further information:
http://guides.rubygems.org
root@a303daf3625d:/# gem install json
Fetching: json-2.1.0.gem (100%)
Building native extensions. This could take a while…
Successfully installed json-2.1.0
1 gem installed

root@a303daf3625d:/# gem list –local

*** LOCAL GEMS ***

bigdecimal (default: 1.3.0)
bundler (1.14.6)
did_you_mean (1.1.0)
io-console (default: 0.4.6)
json (2.1.0, default: 2.0.2)
minitest (5.10.1)
net-telnet (0.1.1)
openssl (default: 2.0.3)
power_assert (0.4.1)
psych (default: 2.2.2)
rake (12.0.0)
rdoc (default: 5.0.0)
rubygems-update (2.6.12)
test-unit (3.2.3)
xmlrpc (0.2.1)

root@a303daf3625d:/# cat >> sample
hai this from ruby docker image

exit

[mohammedrafi@docker ~]$ docker run -it ruby /bin/bash

root@6720e093ba9d:/# cat sample
cat: sample: No such file or directory

[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6720e093ba9d ruby “/bin/bash” 50 seconds ago Exited (1) 5 seconds ago hardcore_bohr
a303daf3625d ruby “/bin/bash” 35 minutes ago Exited (0) 52 seconds ago nifty_newton
77eec9adb89c ubuntu:xenial “/bin/bash” About an hour ago Exited (0) 40 minutes ago elegant_boyd
1c62173e85b5 ubuntu:xenial “/bin/bash” 7 hours ago Exited (0) 6 hours ago modest_wilson
72fae712502d hello-world “/hello” 7 hours ago Exited (0) 7 hours ago elegant_lumiere

[mohammedrafi@docker ~]$ docker restart nifty_newton
nifty_newton
[mohammedrafi@docker ~]$ docker attach nifty_newton
root@a303daf3625d:/#
root@a303daf3625d:/# cat sample
hai this from ruby docker image

#################
Packaging A Customized Container
#################

[mohammedrafi@docker ~]$ docker run -it ubuntu:xenial /bin/bash
root@040c3a906d07:/#

root@040c3a906d07:/# cd

root@040c3a906d07:~# pwd
/root

root@040c3a906d07:~# cat >> one.txt
this is custom image

root@040c3a906d07:~# apt-get update -y

root@040c3a906d07:~# apt-get install telnet openssh-server net-tools -y

root@040c3a906d07:~# useradd test

root@040c3a906d07:~# passwd test
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

root@040c3a906d07:~# which sshd
/usr/sbin/sshd
root@040c3a906d07:~# which telnet
/usr/bin/telnet
root@040c3a906d07:~# grep test /etc/passwd
test:x:1000:1000::/home/test:
root@040c3a906d07:~# grep test /etc/group
test:x:1000:

root@040c3a906d07:~# exit
[mohammedrafi@docker ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
040c3a906d07 ubuntu:xenial “/bin/bash” 22 minutes ago Exited (0) 8 seconds ago epic_yonath
9834e59d9079 ruby “/bin/bash” 25 minutes ago Exited (0) 25 minutes ago thirsty_feynman
6720e093ba9d ruby “/bin/bash” 41 minutes ago Exited (1) 40 minutes ago hardcore_bohr
a303daf3625d ruby “/bin/bash” About an hour ago Exited (0) 25 minutes ago nifty_newton
77eec9adb89c ubuntu:xenial “/bin/bash” About an hour ago Exited (0) About an hour ago elegant_boyd
1c62173e85b5 ubuntu:xenial “/bin/bash” 7 hours ago Exited (0) 7 hours ago modest_wilson
72fae712502d hello-world “/hello” 8 hours ago Exited (0) 8 hours ago elegant_lumiere

[mohammedrafi@docker ~]$ docker commit -m “Already installed ssh and created user test” -a “rafi494” epic_yonath rafi494/sshd:v1
sha256:e55a8760adbd29af3b8d2ff45289ec61d07e8b5f7a1a2f6447a3edd7724e153f

docker commitname or ID of the container” “newimagename:title

[mohammedrafi@docker ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rafi494/sshd v1 e55a8760adbd 35 seconds ago 216 MB

[mohammedrafi@docker ~]$ docker run -it rafi494/sshd:v1 /bin/bash
root@22eeb065ac67:/# which telnet
/usr/bin/telnet
root@22eeb065ac67:/# which sshd
/usr/sbin/sshd
root@22eeb065ac67:/# cat /root/one.txt
this is custom image
root@22eeb065ac67:/# grep test /etc/passwd
test:x:1000:1000::/home/test:
[mohammedrafi@docker ~]$ mkdir build && cd build
[mohammedrafi@docker build]$
[mohammedrafi@docker build]$ vim Dockerfile
# this is a custom ubuntu images with ssh already installed
FROM ubuntu:xenial
MAINTAINER rafi494 mohammedrafi494@gmail.com
RUN apt-get update
RUN apt-get install telnet openssh-server
[mohammedrafi@docker build]$ docker build -t=”rafi494/sshdonly:v2″ .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM ubuntu:xenial
—> f7b3f317ec73
Step 2/4 : MAINTAINER rafi494 mohammedrafi494@gmail.com
—> Running in e2b2f4fabb14
—> 1a0a47743056
Removing intermediate container e2b2f4fabb14
Step 3/4 : RUN apt-get update
—> Running in 62aff63b8e64
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [30.3 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
[mohammedrafi@docker build]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rafi494/sshdonly v2 33881e2e84f3 3 minutes ago 215 MB
rafi494/sshd v1 e55a8760adbd 28 minutes ago 216 MB
ruby latest 64a95ee9eb97 3 days ago 683 MB
ubuntu xenial f7b3f317ec73 10 days ago 117 MB
hello-world latest 48b5124b2768 3 months ago 1.84 kB
[mohammedrafi@docker ~]$ docker run -it rafi494/sshdonly:v2 /bin/bash
root@c9dfec8e06b3:/#
root@4de00218c660:~# grep test /etc/passwd

#################
Running Container Commands With Docker
#################

[mohammedrafi@docker ~]$ docker run -it ubuntu:xenial /bin/bash
root@27cdd8375f14:/#

root@27cdd8375f14:/# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
11 ? 00:00:00 ps

root@27cdd8375f14:/# which sshd
root@27cdd8375f14:/# which telnet
root@27cdd8375f14:/# exit
[mohammedrafi@docker ~]$

[mohammedrafi@docker ~]$ docker ps -a |head -n2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
27cdd8375f14 ubuntu:xenial “/bin/bash” 5 minutes ago Exited (1) About a minute ago gallant_shaw

[mohammedrafi@docker ~]$ docker logs gallant_shaw
10 root 20 0 36656 1704 1260 R 0.0 0.0 0:00.00 top
root@27cdd8375f14:/# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
11 ? 00:00:00 ps
root@27cdd8375f14:/# which sshd
root@27cdd8375f14:/# which telnet
root@27cdd8375f14:/# exit

[mohammedrafi@docker ~]$ docker restart gallant_shaw

[mohammedrafi@docker ~]$ docker exec gallant_shaw cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), …).

if [ “$PS1” ]; then
if [ “$BASH” ] && [ “$BASH” != “/bin/sh” ]; then
# The file bash.bashrc already sets the default PS1.
# PS1=’\h:\w\$ ‘
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ “`id -u`” -eq 0 ]; then
PS1=’# ‘
else
PS1=’$ ‘
fi
fi
fi

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi

#################
Exposing Our Container With Port Redirects
#################
[mohammedrafi@docker ~]$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
36a46ebd5019: Pull complete
57168433389f: Pull complete
332ec8285c50: Pull complete
Digest: sha256:c15f1fb8fd55c60c72f940a76da76a5fccce2fefa0dd9b17967b9e40b0355316
Status: Downloaded newer image for nginx:latest

[mohammedrafi@docker ~]$ docker run -d nginx
a636dd0e6847982587b0e15cd079fa1bf54dd94b89ce2a30d0ae0afc5765c658

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a636dd0e6847 nginx “nginx -g ‘daemon …” About a minute ago Up About a minute 80/tcp modest_stallman

[mohammedrafi@docker ~]$ docker inspect modest_stallman

[mohammedrafi@docker ~]$ docker inspect modest_stallman |grep -i ipaddress
“SecondaryIPAddresses”: null,
“IPAddress”: “172.17.0.2”,
“IPAddress”: “172.17.0.2”,

[mohammedrafi@docker ~]$ elinks 172.17.0.2

Welcome to nginx!
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

[mohammedrafi@docker ~]$ curl -I 172.17.0.2
HTTP/1.1 200 OK
Server: nginx/1.13.0
Date: Fri, 05 May 2017 22:48:17 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 25 Apr 2017 11:30:31 GMT
Connection: keep-alive
ETag: “58ff3357-264”
Accept-Ranges: bytes

[mohammedrafi@docker ~]$ curl -I localhost
curl: (7) Failed connect to localhost:80; Connection refused

[mohammedrafi@docker ~]$ docker run -d -P nginx
8b62fd8bae8e8529cac747a7186d5d4087e6aa004511b74ac1fc2e8e0612e216

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b62fd8bae8e nginx “nginx -g ‘daemon …” 47 seconds ago Up 46 seconds 0.0.0.0:32768->80/tcp competent_bose

[mohammedrafi@docker ~]$ docker run -d -p 80:80 nginx
954ae82f4050d2532722bc44018afa1380a4dec643902356485d3a3cdd562332

[mohammedrafi@docker ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
954ae82f4050 nginx “nginx -g ‘daemon …” 37 seconds ago Up 37 seconds 0.0.0.0:80->80/tcp fervent_volhard
8b62fd8bae8e nginx “nginx -g ‘daemon …” 3 minutes ago Up 3 minutes 0.0.0.0:32768->80/tcp competent_bose

[mohammedrafi@docker ~]$ curl -I 172.17.0.2
HTTP/1.1 200 OK
Server: nginx/1.13.0
Date: Fri, 05 May 2017 22:55:59 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 25 Apr 2017 11:30:31 GMT
Connection: keep-alive
ETag: “58ff3357-264”
Accept-Ranges: bytes

[mohammedrafi@docker ~]$ curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.13.0
Date: Fri, 05 May 2017 22:56:04 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 25 Apr 2017 11:30:31 GMT
Connection: keep-alive
ETag: “58ff3357-264”
Accept-Ranges: bytes
[mohammedrafi@docker ~]$ docker logs fervent_volhard
115.113.77.105 – – [05/May/2017:22:54:59 +0000] “GET / HTTP/1.1” 200 612 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36” “-”
115.113.77.105 – – [05/May/2017:22:54:59 +0000] “GET /favicon.ico HTTP/1.1” 404 571 “http://104.197.110.124/&#8221; “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36” “-”
2017/05/05 22:54:59 [error] 5#5: *1 open() “/usr/share/nginx/html/favicon.ico” failed (2: No such file or directory), client: 115.113.77.105, server: localhost, request: “GET /favicon.ico HTTP/1.1”, host: “104.197.110.124”, referrer: “http://104.197.110.124/&#8221;
172.17.0.1 – – [05/May/2017:22:56:04 +0000] “HEAD / HTTP/1.1” 200 0 “-” “curl/7.29.0” “-”
                           

                     The Dockerfile, Builds and Network Configuration

[root@docker ~]# mkdir Builds && cd Builds

[root@docker Builds]# mkdir RunAsUser && cd RunAsUser

[root@docker RunAsUser]# vim Dockerfile
#This is centos7 images & non previlaged user entry
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
USER jack

[root@docker RunAsUser]# docker build -t centos7/nonroot:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM centos:latest
latest: Pulling from library/centos
93857f76ae30: Pull complete
Digest: sha256:4eda692c08e0a065ae91d74e82fff4af3da307b4341ad61fa61771cc4659af60
Status: Downloaded newer image for centos:latest
—> a8493f5f50ff
Step 2/3 : MAINTAINER mohammedrafi494@gmail.com
—> Running in 68808c8368e2
—> f8bce38a485d
Removing intermediate container 68808c8368e2
Step 3/3 : USER jack
—> Running in 8100fca1b2ee
—> 4c9dc88e3a62
Removing intermediate container 8100fca1b2ee
Successfully built 4c9dc88e3a62
[root@docker RunAsUser]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7/nonroot v1 9ae653db41cd About a minute ago 192 MB

[root@docker RunAsUser]# docker run -it centos7/nonroot:v1 /bin/bash
docker: Error response from daemon: linux spec user: unable to find user jack: no matching entries in passwd file.

[root@docker RunAsUser]# vim Dockerfile
#This is centos7 images & non previlaged user entry
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash user
USER jack
[root@docker RunAsUser]# docker build -t centos7/nonroot:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM centos:latest
—> a8493f5f50ff
Step 2/4 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/4 : RUN useradd -ms /bin/bash jack
—> Running in 8de23c098c90
—> 93764e893abd
Removing intermediate container 8de23c098c90
Step 4/4 : USER jack
—> Running in 31fae3bd2d7f
—> 69b006a58bc9
Removing intermediate container 31fae3bd2d7f
Successfully built 69b006a58bc9

[root@docker RunAsUser]# docker run -it centos7/nonroot:v1 /bin/bash

[jack@b9ed3dfb25f2 /]$ whoami
jack
[jack@8b4b4fd69a43 /]$ su –
Password:
su: Authentication failure
[jack@8b4b4fd69a43 /]$ exit

[root@docker RunAsUser]# docker exec -u 0 -it jovial_engelbart /bin/bash
[root@8b4b4fd69a43 /]#
[root@8b4b4fd69a43 /]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jack 1 0.0 0.0 11768 1684 ? Ss+ 11:07 0:00 /bin/bash
root 29 0.7 0.0 11768 1884 ? Ss 11:11 0:00 /bin/bash
root 41 0.0 0.0 47440 1684 ? R+ 11:11 0:00 ps aux

#############
Dockerfile Directives: RUN Order of Execution
#############

[root@docker ~]# mkdir CustomMessage
[root@docker ~]# cd CustomMessage/
[root@docker CustomMessage]# vim Dockerfile
#This is centos7 images & non previlaged user entry
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash jack
RUN echo “EXPORT 192.168.0.0/24” >> /etc/exports.list
USER jack
[root@docker CustomMessage]# docker build -t centos7/config:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/5 : FROM centos:latest
—> a8493f5f50ff
Step 2/5 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/5 : RUN useradd -ms /bin/bash jack
—> Using cache
—> 93764e893abd
Step 4/5 : RUN echo “EXPORT 192.168.0.0/24” >> /etc/exports.list
—> Running in c1eaa315552f
—> 5b55293220d4
Removing intermediate container c1eaa315552f
Step 5/5 : USER jack
—> Running in d1e3105153a4
—> 390b81ef6ca5
Removing intermediate container d1e3105153a4
Successfully built 390b81ef6ca5

[root@docker CustomMessage]# docker run -it centos7/config:v1 /bin/bash
[jack@6cb03b18ed66 /]$ cat /etc/exports.list
EXPORT 192.168.0.0/24

#############
Dockerfile Directives: ENV
#############

[root@docker ~]# mkdir javainstall && cd javainstall

[root@docker javainstall]# vim Dockerfile
#This is centos7 images & non previlaged user entry
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash jack
RUN yum update -y
RUN yum install -y net-tools wget
RUN cd ~ && yum install java-1.8.0-openjdk -y
USER jack
RUN cd ~ && echo “export JAVA_HOME=/usr/java/jdk1.8.0/jre” >> /home/jack/.bashrc
ENV JAVA_BIN /usr/java/jdk1.8.0/jre/bin

[root@docker javainstall]# docker build -t centos7/java8:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/8 : FROM centos:latest
—> a8493f5f50ff
Step 2/8 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/8 : RUN useradd -ms /bin/bash jack
—> Using cache
—> 93764e893abd
Step 4/8 : RUN yum update -y
—> Using cache
—> d478f5b65d3d
Step 5/8 : RUN yum install -y net-tools wget
—> Using cache
—> 87766a01d539
Step 6/8 : RUN cd ~ && yum install java-1.8.0-openjdk -y
—> Using cache
—> 669bd134ea5b
Step 7/8 : USER jack
—> Using cache
—> 4b949f676a18
Step 8/8 : RUN cd ~ && echo “export JAVA_HOME=/usr/java/jdk1.8.0/jre” >> /home/jack/.bashrc
—> Using cache
—> 0518eefbfb7a
Step 9/9 : ENV JAVA_BIN /usr/java/jdk1.8.0/jre/bin
—> Running in 8d6d81aaa7b2
—> e15ebe1ce190
Removing intermediate container 8d6d81aaa7b2
Successfully built e15ebe1ce190
[root@docker javainstall]# docker images

[root@docker javainstall]# docker run -it centos7/java8:v1 /bin/bash
[jack@1b29867f6592 /]$
[jack@1b29867f6592 /]$ env |grep -i java
JAVA_HOME=/usr/java/jdk1.8.0/jre

[root@docker ~]# mkdir EchoServer && cd EchoServer

[root@docker EchoServer]# vim Dockerfile
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash jack
CMD “echo” “this is a custom container messge for our students “
USER jack

[root@docker EchoServer]# docker build -t centos7/cmd:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/5 : FROM centos:latest
—> a8493f5f50ff
Step 2/5 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/5 : RUN useradd -ms /bin/bash jack
—> Using cache
—> 93764e893abd
Step 4/5 : CMD “echo” “this is a custom container messge for our students ”
—> Running in 55a7539ee1aa
—> d14164cf5fc6
Removing intermediate container 55a7539ee1aa
Step 5/5 : USER jack
—> Running in d9d242beb1e4
—> 0e0ef6026670
Removing intermediate container d9d242beb1e4
Successfully built 0e0ef6026670

#############
Dockerfile Directives: CMD vs. RUN
#############

[root@docker ~]# mkdir EchoServer ; cd EchoServer
[root@docker EchoServer]#

[root@docker EchoServer]# vim Dockerfile
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash jack
CMD “echo” “this is a custom message”
USER jack

[root@docker EchoServer]# docker build -t centos7/echo:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/5 : FROM centos:latest
—> a8493f5f50ff
Step 2/5 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/5 : RUN useradd -ms /bin/bash jack
—> Using cache
—> 93764e893abd
Step 4/5 : CMD “echo” “this is a custom message”
—> Running in abae9872b588
—> 1c39d3aad610
Removing intermediate container abae9872b588
Step 5/5 : USER jack
—> Running in d5710dca757b
—> 0374d9bc070a
Removing intermediate container d5710dca757b
Successfully built 0374d9bc070a

[root@docker EchoServer]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7/echo v1 0374d9bc070a 2 minutes ago 193 MB

[root@docker EchoServer]# docker run centos7/echo:v1
this is a custom message

#############
Dockerfile Directives: ENTRYPOINT
#############

[root@docker ~]# mkdir Entry;cd Entry
[root@docker Entry]# vim Dockerfile
MAINTAINER mohammedrafi494@gmail.com
RUN useradd -ms /bin/bash jack
ENTRYPOINT echo “this command will display this message on every container that is run from it “
USER jack

[root@docker Entry]# docker build -t centos7/entry:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/5 : FROM centos:latest
—> a8493f5f50ff
Step 2/5 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/5 : RUN useradd -ms /bin/bash jack
—> Using cache
—> 93764e893abd
Step 4/5 : ENTRYPOINT echo “this command will display this message on every container that is run from it ”
—> Running in f7cd5851714b
—> 936c4e45f5da
Removing intermediate container f7cd5851714b
Step 5/5 : USER jack
—> Running in 10fb48f63201
—> 2a7b8511d21c
Removing intermediate container 10fb48f63201
Successfully built 2a7b8511d21c

[root@docker Entry]# docker run centos7/entry:v1
this command will display this message on every container that is run from it

[root@docker Entry]# docker run centos7/echo:v1 /bin/echo “from lab”
from lab

[root@docker Entry]# docker run centos7/entry:v1 /bin/bash
this command will display this message on every container that is run from it

[root@docker Entry]# docker run centos7/entry:v1 /bin/echo “hai”
this command will display this message on every container that is run from it

#############
Dockerfile Directives: EXPOSE
#############
[root@docker ~]# mkdir ApacheInstallation ; cd ApacheInstallation
[root@docker ApacheInstallation]#

[root@docker ApacheInstallation]# vim Dockerfile
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com

RUN yum update -y
RUN yum install -y httpd net-tools

RUN echo “this is a custom file build during the image creation” > /var/www/html/index.html

ENTRYPOINT apachectl “-DFOREGROUND”
[root@docker ApacheInstallation]# docker build -t centos7/apache:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/6 : FROM centos:latest
—> a8493f5f50ff
Step 2/6 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/6 : RUN yum update -y
—> Running in 59348f911c74
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: dist1.800hosting.com
* extras: centos.mirrors.tds.net
* updates: mirror.sesp.northwestern.edu
Resolving Dependencies
–> Running transaction check
—> Package bind-license.noarch 32:9.9.4-38.el7_3.2 will be updated
.
.
.
Complete!
—> f79ae5bbd8bd
Removing intermediate container 59348f911c74
Step 4/6 : RUN yum install -y httpd net-tools
—> Running in 58709a2bf668
.
.
.
Complete!
—> 08dab0eae47d
Removing intermediate container 58709a2bf668
Step 5/6 : RUN echo “this is a custom file build during the image creation” > /var/www/html/index.html
—> Running in e8991604ecbb
—> 59bc568b92c8
Removing intermediate container e8991604ecbb
Step 6/6 : ENTRYPOINT apachectl “-DFOREGROUND”
—> Running in 27add8efaa11
—> 8fae6f4d604d
Removing intermediate container 27add8efaa11
Successfully built 8fae6f4d604d
[root@docker ApacheInstallation]# docker images | head -n2
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7/apache v1 8fae6f4d604d About a minute ago 374 MB
[root@docker ApacheInstallation]# docker run -d –name apacheweb1 centos7/apache:v1
53a2e4a6d9604d4f7a83c939e6113f23b9c42bece4bf3020c4a097b3d30a2840

[root@docker ApacheInstallation]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53a2e4a6d960 centos7/apache:v1 “/bin/sh -c ‘apach…” 15 seconds ago Up 14 seconds apacheweb1

[root@docker ApacheInstallation]# docker inspect apacheweb1

[root@docker ApacheInstallation]# docker inspect apacheweb1 |grep -i ipaddress
“SecondaryIPAddresses”: null,
“IPAddress”: “172.17.0.5”,
“IPAddress”: “172.17.0.5”,

[root@docker ApacheInstallation]# elinks http://172.17.0.5

[root@docker ApacheInstallation]# docker exec apacheweb1 /bin/cat /var/www/html/index.html
this is a custom file build during the image creation

[root@docker ApacheInstallation]# docker stop apacheweb1
apacheweb1

[root@docker ApacheInstallation]# docker run -d –name apacheweb2 -p 8080:80 centos7/apache:v1
3c2766d1235da65406d31505d367214332f9bfec5f39ac7b377a6a3da5994c50

[root@docker ApacheInstallation]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3c2766d1235d centos7/apache:v1 “/bin/sh -c ‘apach…” 7 seconds ago Up 6 seconds 0.0.0.0:8080->80/tcp apacheweb2

[root@docker ApacheInstallation]# elinks http://localhost:8080

[root@docker ApacheInstallation]# docker stop apacheweb2
apacheweb2

[root@docker ApacheInstallation]# vim Dockerfile
FROM centos:latest
MAINTAINER mohammedrafi494@gmail.com

RUN yum update -y
RUN yum install -y httpd net-tools

RUN echo “this is a custom file build during the image creation” > /var/www/html/index.html

EXPOSE 80
ENTRYPOINT apachectl “-DFOREGROUND”

[root@docker ApacheInstallation]# docker build -t centos7/apache:v1 .
Sending build context to Docker daemon 2.048 kB
Step 1/7 : FROM centos:latest
—> a8493f5f50ff
Step 2/7 : MAINTAINER mohammedrafi494@gmail.com
—> Using cache
—> 7b07dfec86a4
Step 3/7 : RUN yum update -y
—> Using cache
—> f79ae5bbd8bd
Step 4/7 : RUN yum install -y httpd net-tools
—> Using cache
—> 08dab0eae47d
Step 5/7 : RUN echo “this is a custom file build during the image creation” > /var/www/html/index.html
—> Using cache
—> 59bc568b92c8
Step 6/7 : EXPOSE 80
—> Running in 8a6414cee330
—> 6ffac908afec
Removing intermediate container 8a6414cee330
Step 7/7 : ENTRYPOINT apachectl “-DFOREGROUND”
—> Running in 80bbdfdac87b
—> 191600c8f5f8
Removing intermediate container 80bbdfdac87b
Successfully built 191600c8f5f8

[root@docker ApacheInstallation]# docker run -d –name apacheweb3 -P centos7/apache:v1
8868af10516b3a3ce4236be62abb6446c42ee8e24c8de7392ee5029388e7e82a

[root@docker ApacheInstallation]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8868af10516b centos7/apache:v1 “/bin/sh -c ‘apach…” 23 seconds ago Up 22 seconds 0.0.0.0:32769->80/tcp apacheweb3

[root@docker ApacheInstallation]# elinks http://localhost:32768

#############
Container Volume Management
#############

[root@docker ~]# docker run -it –name voltest1 -v /mydata centos:latest /bin/bash

[root@6f5b3e449d83 /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 10G 3.6G 6.5G 36% /
tmpfs tmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 10G 3.6G 6.5G 36% /mydata
shm tmpfs 64M 0 64M 0% /dev/shm
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/firmware

[root@6f5b3e449d83 /]# ls -l /mydata/
total 0
[root@6f5b3e449d83 /]# echo “this is my test container volume” > /mydata/mytext

[root@6f5b3e449d83 /]# ls -l /mydata/
total 4
-rw-r–r–. 1 root root 33 May 8 18:59 mytext

[root@docker ~]# docker inspect voltest1 |grep -i destination
“Destination”: “/mydata”,

[root@docker ~]# ls -l /var/lib/docker/
total 24
drwx——. 38 root root 4096 May 8 19:09 containers
drwx——. 3 root root 20 May 5 12:42 image
drwxr-x—. 3 root root 18 May 5 12:42 network
drwx——. 106 root root 12288 May 8 19:09 overlay
drwx——. 4 root root 30 May 5 12:42 plugins
drwx——. 2 root root 6 May 5 12:42 swarm
drwx——. 2 root root 6 May 8 11:24 tmp
drwx——. 2 root root 6 May 5 12:42 trust
drwx——. 4 root root 4096 May 8 19:09 volumes
[root@docker ~]# ls -l /var/lib/docker/volumes/
total 24
drwxr-xr-x. 3 root root 18 May 8 18:57 1051b305c418d754426e1a7b3ddbf53dc377255eb587f23599b2c14da8988757
-rw——-. 1 root root 32768 May 8 19:09 metadata.db

[root@docker ~]# ls -l /var/lib/docker/volumes/1051b305c418d754426e1a7b3ddbf53dc377255eb587f23599b2c14da8988757/
total 0
drwxr-xr-x. 2 root root 19 May 8 18:59 _data

[root@docker ~]# ls -l /var/lib/docker/volumes/1051b305c418d754426e1a7b3ddbf53dc377255eb587f23599b2c14da8988757/_data/
total 4
-rw-r–r–. 1 root root 33 May 8 18:59 mytext

[root@docker ~]# cat /var/lib/docker/volumes/1051b305c418d754426e1a7b3ddbf53dc377255eb587f23599b2c14da8988757/_data/mytext
this is my test container volume

[root@docker ~]# echo “this is from host” > /var/lib/docker/volumes/1051b305c418d754426e1a7b3ddbf53dc377255eb587f23599b2c14da8988757/_data/host.txt

[root@6f5b3e449d83 /]# ls -l /mydata/
total 8
-rw-r–r–. 1 root root 18 May 8 19:16 host.txt
-rw-r–r–. 1 root root 33 May 8 18:59 mytext
[root@6f5b3e449d83 /]# cat /mydata/host.txt
this is from host

[root@docker ~]# mkdir Myhostdir
[root@docker ~]# cd Myhostdir/
[root@docker Myhostdir]# echo “this is file one” > one.txt
[root@docker Myhostdir]# echo “this is file two” > two.txt
[root@docker Myhostdir]# echo “this is file three” > three.txt
[root@docker Myhostdir]# chmod 755 one.txt

[root@docker Myhostdir]# docker run -it –name volumetest2 -v /root/Myhostdir/:/mydata centos:latest /bin/bash

[root@bd0556962c6b /]# ls -l /mydata/
total 12
-rwxr-xr-x. 1 root root 17 May 8 19:28 one.txt
-rw-r–r–. 1 root root 19 May 8 19:29 three.txt
-rw-r–r–. 1 root root 17 May 8 19:28 two.txt

[root@bd0556962c6b /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 10G 3.6G 6.5G 36% /
tmpfs tmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 10G 3.6G 6.5G 36% /mydata
shm tmpfs 64M 0 64M 0% /dev/shm
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/firmware

#############
Docker Network: List and Inspect
#############

[root@docker ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
164df530e694 bridge bridge local
22023156a486 host host local
a661140fd0e5 none null local

[root@docker ~]# docker network ls –no-trunc
NETWORK ID NAME DRIVER SCOPE
164df530e6942fade5210d39c80b6694e0fdc8bc7192c67bf050e64df2f0d241 bridge bridge local
22023156a486c7e66c7e080bca11aaf3a28f2817893e08a0f7fc5cda276d7936 host host local
a661140fd0e595fe8a85d1b5feea8c2953eb4e2cca09916125b795874b37ace1 none null local

[root@docker ~]# docker network inspect bridge
[
{
“Name”: “bridge”,
“Id”: “164df530e6942fade5210d39c80b6694e0fdc8bc7192c67bf050e64df2f0d241”,
“Created”: “2017-05-05T12:42:36.753804246Z”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: [
{
“Subnet”: “172.17.0.0/16”
}
]
},
“Internal”: false,
“Attachable”: false,
“Containers”: {
“6f5b3e449d834e04ae0d1a44b27d3e70a2961c434da3032ebb0f948a48bf6907”: {
“Name”: “voltest1”,
“EndpointID”: “84c6b484ab30560a08243b65608525766f6fd2229a58ea1f3793f3241534e010”,
“MacAddress”: “02:42:ac:11:00:02”,
“IPv4Address”: “172.17.0.2/16”,
“IPv6Address”: “”
}
},
“Options”: {
“com.docker.network.bridge.default_bridge”: “true”,
“com.docker.network.bridge.enable_icc”: “true”,
“com.docker.network.bridge.enable_ip_masquerade”: “true”,
“com.docker.network.bridge.host_binding_ipv4”: “0.0.0.0”,
“com.docker.network.bridge.name”: “docker0”,
“com.docker.network.driver.mtu”: “1500”
},
“Labels”: {}
}
]

#######################
[root@docker ~]# docker network inspect host
[
{
“Name”: “host”,
“Id”: “22023156a486c7e66c7e080bca11aaf3a28f2817893e08a0f7fc5cda276d7936”,
“Created”: “2017-05-05T12:42:36.742244911Z”,
“Scope”: “local”,
“Driver”: “host”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: []
},
“Internal”: false,
“Attachable”: false,
“Containers”: {},
“Options”: {},
“Labels”: {}
}
]
#########################
[root@docker ~]# docker network inspect none
[
{
“Name”: “none”,
“Id”: “a661140fd0e595fe8a85d1b5feea8c2953eb4e2cca09916125b795874b37ace1”,
“Created”: “2017-05-05T12:42:36.727198585Z”,
“Scope”: “local”,
“Driver”: “null”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: []
},
“Internal”: false,
“Attachable”: false,
“Containers”: {},
“Options”: {},
“Labels”: {}
}
]
##############################

#############
Docker Network: Create and Remove
#############

[root@docker ~]# man docker-network-create

[root@docker ~]# docker network create –subnet 10.1.0.0/24 mybridge01
fa665d98b2cf71b427b10b42889fe504dc6a236dd889026349958301a0c14b7e

[root@docker ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
164df530e694 bridge bridge local
22023156a486 host host local
fa665d98b2cf mybridge01 bridge local
a661140fd0e5 none null local

[root@docker ~]# ifconfig
br-fa665d98b2cf: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 10.1.0.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 02:42:e2:3e:19:24 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@docker ~]# docker network rm mybridge01
mybridge01
[root@docker ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
164df530e694 bridge bridge local
22023156a486 host host local
a661140fd0e5 none null local

#############
Docker Network: Assign to Containers
#############

[root@docker ~]# docker network create –subnet 10.1.0.0/16 –gateway 10.1.0.1 –ip-range=10.1.4.0/24 –driver=bridge –label=host4network bridge04
f9917f3eb3bcd79cd48382060a8b5df9f90c0aa7be6ad346cc15cf9838740f65

[root@docker ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
164df530e694 bridge bridge local
f9917f3eb3bc bridge04 bridge local
22023156a486 host host local
a661140fd0e5 none null local

[root@docker ~]# docker network inspect bridge04
[
{
“Name”: “bridge04”,
“Id”: “f9917f3eb3bcd79cd48382060a8b5df9f90c0aa7be6ad346cc15cf9838740f65”,
“Created”: “2017-05-08T20:38:44.974220061Z”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “10.1.0.0/16”,
“IPRange”: “10.1.4.0/24”,
“Gateway”: “10.1.0.1”
}
]
},
“Internal”: false,
“Attachable”: false,
“Containers”: {},
“Options”: {},
“Labels”: {
“host4network”: “”
}
}
]

[root@docker ~]# ifconfig
br-f9917f3eb3bc: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 10.1.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ad:b7:b9:e8 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@docker ~]# docker run -it –name nettest1 –net bridge04 centos:latest /bin/bash
[root@b1a8caff05cb /]# yum install net-tools -y

[root@b1a8caff05cb /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.4.0 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:aff:fe01:400 prefixlen 64 scopeid 0x20<link>
ether 02:42:0a:01:04:00 txqueuelen 0 (Ethernet)
[root@docker ~]# docker run -it –name nettest2 –net bridge04 –ip 10.1.4.100 centos:latest /bin/bash
[root@c48fe019eeda /]#

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c48fe019eeda centos:latest “/bin/bash” 30 seconds ago Up 29 seconds nettest2

[root@c48fe019eeda /]# yum update -y

[root@c48fe019eeda /]# yum install net-tools -y

[root@c48fe019eeda /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.4.100 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:aff:fe01:464 prefixlen 64 scopeid 0x20<link>
ether 02:42:0a:01:04:64 txqueuelen 0 (Ethernet)
RX packets 1614 bytes 22624051 (21.5 MiB)

[root@docker ~]# docker inspect nettest2 |grep -i ipaddress
“SecondaryIPAddresses”: null,
“IPAddress”: “”,
“IPAddress”: “10.1.4.100”,
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1a8caff05cb centos:latest “/bin/bash” 43 seconds ago Up 42 seconds nettest1

[root@docker ~]# ping 10.1.4.100
PING 10.1.4.100 (10.1.4.100) 56(84) bytes of data.
64 bytes from 10.1.4.100: icmp_seq=1 ttl=64 time=0.075 ms

#############
Inspect Container Processes
#############
[root@docker ~]# docker start epic_yonath
epic_yonath

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
040c3a906d07 ubuntu:xenial “/bin/bash” 3 days ago Up 2 seconds epic_yonath

[root@docker ~]# docker exec epic_yonath /bin/ps aux |grep bash
root 1 0.0 0.0 18228 1920 ? Ss+ 21:28 0:00 /bin/bash

[root@docker ~]# docker top epic_yonath
UID PID PPID C STIME TTY TIME CMD
root 24791 24778 0 21:28 pts/1 00:00:00 /bin/bash

root@040c3a906d07:/# apt-get upgrade -y

[root@docker ~]# docker top epic_yonath
UID PID PPID C STIME TTY TIME CMD
root 24791 24778 0 21:28 pts/1 00:00:00 /bin/bash
root 24918 24905 0 21:33 pts/2 00:00:00 /bin/bash
root 25258 24918 56 21:36 pts/2 00:00:01 apt-get upgrade -y

[root@docker ~]# docker stats epic_yonath
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
epic_yonath 0.00% 118.3 MiB / 3.613 GiB 3.20% 17.4 MB / 31.2 kB 38.4 MB / 97 MB 2

[root@docker ~]# docker rm docker ps -a -q

############
Naming Our Containers
#############

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a16b4149b81c nginx:latest “nginx -g ‘daemon …” 51 minutes ago Up 51 minutes 0.0.0.0:32772->80/tcp naughty_newton

[root@docker ~]# docker rename naughty_newton myownname

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a16b4149b81c nginx:latest “nginx -g ‘daemon …” 53 minutes ago Up 53 minutes 0.0.0.0:32772->80/tcp myownname

#######
Docker Events
#############

[root@docker ~]# docker events –since ‘1h’
2017-05-09T01:11:34.899323577Z container rename a16b4149b81c016a9e119cde8f69176a7f06a80135d1fd5ebef23c0b66c3ba2e (image=nginx:latest, name=myownname, oldName=/naughty_newton)
2017-05-09T01:26:11.220564950Z image pull wordpress:latest (name=wordpress)

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b96235ec560 nginx:latest “nginx -g ‘daemon …” About an hour ago Up About an hour 0.0.0.0:8080->80/tcp brave_austin
6504adf090b0 nginx:latest “nginx -g ‘daemon …” 2 hours ago Up 2 hours 0.0.0.0:32771->80/tcp objective_bhabha

[root@docker ~]# docker rename brave_austin rafi
[root@docker ~]# docker events –filter event=rename
2017-05-09T01:50:23.267238989Z container rename 6b96235ec560ce41648700500afb1d6ae96ee0c52c7fa64a9118b33e5677b246 (image=nginx:latest, name=rafi, oldName=/brave_austin)

#############
Managing and Removing Base Images
#############

[root@docker ~]# docker images

[root@docker ~]# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Deleted: sha256:48b5124b2768d2b917edcb640435044a97967015485e812545546cbed5cf0233
Deleted: sha256:98c944e98de8d35097100ff70a31083ec57704be0991a92c51700465e4544d08

[root@docker ~]# docker run -it ubuntu:xenial /bin/bash
root@08d51371520d:/# apt-get update -y

[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08d51371520d ubuntu:xenial “/bin/bash” 51 seconds ago Up 50 seconds ecstatic_sinoussi

[root@docker ~]# docker rmi ubuntu:xenial
Error response from daemon: conflict: unable to remove repository reference “ubuntu:xenial” (must force) – container 08d51371520d is using its referenced image f7b3f317ec73

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08d51371520d ubuntu:xenial “/bin/bash” 3 minutes ago Up 3 minutes ecstatic_sinoussi

[root@docker ~]# docker rm ecstatic_sinoussi
Error response from daemon: You cannot remove a running container 08d51371520d686732db04ebdc74e42ca7fea180c05e0b47428f4bab90d4dc78. Stop the container before attempting removal or use -f

[root@docker ~]# docker stop ecstatic_sinoussi
ecstatic_sinoussi

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b96235ec560 46102226f2fd “nginx -g ‘daemon …” 2 hours ago Up 2 hours 0.0.0.0:8080->80/tcp rafi
6504adf090b0 46102226f2fd “nginx -g ‘daemon …” 2 hours ago Up 2 hours 0.0.0.0:32771->80/tcp objective_bhabha
[root@docker ~]# docker rm ecstatic_sinoussi
ecstatic_sinoussi

[root@docker ~]# docker rmi ubuntu:xenial
Untagged: ubuntu:xenial
Untagged: ubuntu@sha256:f3a61450ae43896c4332bda5e78b453f4a93179045f20c8181043b26b5e79028

[root@docker ~]# docker rmi nginx
Error response from daemon: conflict: unable to remove repository reference “nginx” (must force) – container 6504adf090b0 is using its referenced image 46102226f2fd

[root@docker ~]# docker rmi nginx -f
Untagged: nginx:latest
Untagged: nginx@sha256:c15f1fb8fd55c60c72f940a76da76a5fccce2fefa0dd9b17967b9e40b0355316

[root@docker ~]# docker rmi $(docker images -f dangling=true -q)

#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)

 

#######
Saving and Loading Docker Images
#############

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

[root@docker ~]# docker pull centos:latest
latest: Pulling from library/centos
Digest: sha256:4eda692c08e0a065ae91d74e82fff4af3da307b4341ad61fa61771cc4659af60
Status: Downloaded newer image for centos:latest
[root@docker ~]# docker run -it centos:latest /bin/bash

[root@88edf9927185 /]# yum update -y

[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88edf9927185 centos:latest “/bin/bash” 38 seconds ago Exited (0) 4 seconds ago unruffled_lumiere

[root@docker ~]# docker commit unruffled_lumiere centos:mine
sha256:4345f8671cb19016c2bf5818163ce5199c750e3e3c710e1fe07f5bc321181506

[root@docker ~]# docker rm unruffled_lumiere
unruffled_lumiere

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mine 4345f8671cb1 About a minute ago 321 MB
centos latest a8493f5f50ff 4 weeks ago 192 MB

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@docker ~]# docker save centos:latest > centos.latest.tar
[root@docker ~]# docker save -o centos.latest.tar centos:latest
[root@docker ~]# docker save –output centos.latest.tar centos:latest

[root@docker ~]# ls -l centos.latest.tar
-rw——-. 1 root root 200109568 May 9 07:48 centos.latest.tar
[root@docker ~]# tar -tvf centos.latest.tar
drwxr-xr-x 0/0 0 2017-04-06 20:14 9137f32861a5b3e44beef7ac24ed1bffc1f178c37a761364107934a6d36178ec/
-rw-r–r– 0/0 3 2017-04-06 20:14 9137f32861a5b3e44beef7ac24ed1bffc1f178c37a761364107934a6d36178ec/VERSION
-rw-r–r– 0/0 1328 2017-04-06 20:14 9137f32861a5b3e44beef7ac24ed1bffc1f178c37a761364107934a6d36178ec/json
-rw-r–r– 0/0 200099840 2017-04-06 20:14 9137f32861a5b3e44beef7ac24ed1bffc1f178c37a761364107934a6d36178ec/layer.tar
-rw-r–r– 0/0 1832 2017-04-06 20:14 a8493f5f50ffda70c2eeb2d09090debf7d39c8ffcd63b43ff81b111ece6f28bf.json
-rw-r–r– 0/0 202 1970-01-01 00:00 manifest.json
-rw-r–r– 0/0 89 1970-01-01 00:00 repositories

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mine 4345f8671cb1 9 minutes ago 321 MB
centos latest a8493f5f50ff 4 weeks ago 192 MB
[root@docker ~]# docker rmi centos:latest
Untagged: centos:latest
Untagged: centos@sha256:4eda692c08e0a065ae91d74e82fff4af3da307b4341ad61fa61771cc4659af60

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mine 4345f8671cb1 9 minutes ago 321 MB

[root@docker ~]# docker load < centos.latest.tar
Loaded image: centos:latest

[root@docker ~]# docker load –input centos.latest.tar

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mine 4345f8671cb1 10 minutes ago 321 MB
centos latest a8493f5f50ff 4 weeks ago 192 MB

[root@docker ~]# gzip centos.latest.tar
[root@docker ~]# ls -lh centos.latest.tar.gz
-rw——-. 1 root root 68M May 9 07:48 centos.latest.tar.gz

#############
Image History
#############

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos mine 4345f8671cb1 About an hour ago 321 MB
centos latest a8493f5f50ff 4 weeks ago 192 MB
[root@docker ~]#

[root@docker ~]# docker history centos:mine
IMAGE CREATED CREATED BY SIZE COMMENT
4345f8671cb1 About an hour ago /bin/bash 128 MB
a8493f5f50ff 4 weeks ago /bin/sh -c #(nop) CMD [“/bin/bash”] 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) LABEL name=CentOS Base … 0 B
<missing> 4 weeks ago /bin/sh -c #(nop) ADD file:807143da05d7013… 192 MB

[root@docker ~]# docker history centos:mine –quiet
4345f8671cb1
a8493f5f50ff
<missing>
<missing>

#############
Pushing to Docker Hub
#############

[root@docker ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don’t have a Docker ID, head over to https://hub.docker.com to create one.
Username: rafi494
Password:
Login Succeeded
[root@docker ~]# cd .docker/
[root@docker .docker]# cat config.json
{
“auths”: {
https://index.docker.io/v1/&#8221;: {
“auth”: “cmFmaTQ5NDpJbmQqOTYzLg==”
}
}
}

[root@docker ~]# docker push centos:mine

[root@docker .docker]# docker logout
Removing login credentials for https://index.docker.io/v1/

                               Integration and Use Cases

#############
Building a Web Farm for Development and Testing
#############

[root@docker ~]# docker pull centos:centos6
centos6: Pulling from library/centos
e4f33982c81a: Pull complete
Digest: sha256:4bea14b310a92cb334a0a47578f01a6f81b020577381fc2e1fbee4edbf37717e
Status: Downloaded newer image for centos:centos6

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos centos6 30365b2e827c 4 weeks ago 195 MB

[root@docker ~]# docker run -it centos:centos6 /bin/bash
[root@deebebc3a9f0 /]#

[root@deebebc3a9f0 /]# yum install epel-release -y net-tools wget

[root@deebebc3a9f0 /]# yum update -y

[root@deebebc3a9f0 /]# yum install which sudo httpd php openssh-server vim -y

[root@deebebc3a9f0 ~]# which service
/sbin/service

[root@deebebc3a9f0 ~]# vim .bashrc
#add the service that we want to start
/sbin/service httpd start
/sbin/service sshd start
[root@docker ~]# docker commit deebebc3a9f0 centos6:baseweb
sha256:7ffd23808b66741c0de5f8f1dac8c0b49c780d3da131275b0058cadafd992d0f

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6 baseweb 7ffd23808b66 37 seconds ago 529 MB
centos centos6 30365b2e827c 4 weeks ago 195 MB

[root@docker ~]# docker run -it centos6:baseweb
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.2 for ServerName
[ OK ]
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@fed774b6f4ac /]# service httpd status
httpd (pid 30) is running…

[root@fed774b6f4ac /]# service sshd status
openssh-daemon (pid 76) is running…
[root@32c561b02214 /]#

 

Advertisements

One thought on “latest docker version on centos-7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s