docker basics

[root@docker ~]# cat > /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

[root@docker ~]# yum install docker-engine -y

[root@docker ~]# docker –version
Docker version 1.13.0, build 49bf474

[root@docker ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 3
Server Version: 1.13.0
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: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.2.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.613 GiB
Name: docker.c.rich-operand-154505.internal
ID: U5JX:ELSX:UX4I:7PVS:LJBS:P65S:TBYS:WWWB:U6SU:QXNR:AW2K:PH4B
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

[root@docker ~]# service docker status
Redirecting to /bin/systemctl status docker.service
● docker.service – Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com

[root@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 86179sec preferred_lft 86179sec
[root@docker ~]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@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 86157sec preferred_lft 86157sec
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:34:35:a5:48 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@docker ~]# docker run busybox echo “Hello First docker box”
Unable to find image ‘busybox:latest’ locally
latest: Pulling from library/busybox
4b0bc1c4050b: Pull complete
Digest: sha256:817a12c32a39bbe394944ba49de563e085f1d3c5266eb8e9723256bc4448680e
Status: Downloaded newer image for busybox:latest
Hello First docker box

[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5dfe72d1fdf busybox “echo ‘Hello First…” 14 seconds ago Exited (0) 13 seconds ago youthful_banach

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

[root@docker ~]# docker run busybox ping google.com -c3
PING google.com (64.233.191.138): 56 data bytes
64 bytes from 64.233.191.138: seq=0 ttl=52 time=0.965 ms
64 bytes from 64.233.191.138: seq=1 ttl=52 time=0.446 ms
64 bytes from 64.233.191.138: seq=2 ttl=52 time=0.421 ms

— google.com ping statistics —
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.421/0.610/0.965 ms

[root@docker ~]# docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s… 5393 [OK]
[root@docker ~]# docker run -it ubuntu /bin/bash
Unable to find image ‘ubuntu:latest’ locally
latest: Pulling from library/ubuntu
8aec416115fd: Pull complete
695f074e24e3: Pull complete
946d6c48c2a7: Pull complete
bc7277e579f0: Pull complete
2508cbcde94b: Pull complete
Digest: sha256:71cd81252a3563a03ad8daee81047b62ab5d892ebbfbf71cf53415f29c130950
Status: Downloaded newer image for ubuntu:latest
[root@docker ~]# docker run –help

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

Run a command in a new container

Options:
–add-host list Add a custom host-to-IP mapping (host:ip) (default [])
-a, –attach list Attach to STDIN, STDOUT or STDERR (default [])
–blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
–blkio-weight-device weighted-device Block IO weight (relative device weight) (default [])
–cap-add list Add Linux capabilities (default [])
–cap-drop list Drop Linux capabilities (default [])
–cgroup-parent string Optional parent cgroup for the container
–cidfile string Write the container ID to the file
–cpu-count int CPU count (Windows only)
–cpu-percent int CPU percent (Windows only)
–cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
–cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
–cpu-rt-period int Limit CPU real-time period in microseconds
–cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, –cpu-shares int CPU shares (relative weight)
–cpus decimal Number of CPUs (default 0.000)
–cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
–cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
–credentialspec string Credential spec for managed service account (Windows only)
-d, –detach Run container in background and print container ID
–detach-keys string Override the key sequence for detaching a container
–device list Add a host device to the container (default [])
–device-read-bps throttled-device Limit read rate (bytes per second) from a device (default [])
–device-read-iops throttled-device Limit read rate (IO per second) from a device (default [])
–device-write-bps throttled-device Limit write rate (bytes per second) to a device (default [])
–device-write-iops throttled-device Limit write rate (IO per second) to a device (default [])
–disable-content-trust Skip image verification (default true)
–dns list Set custom DNS servers (default [])
–dns-option list Set DNS options (default [])
–dns-search list Set custom DNS search domains (default [])
–entrypoint string Overwrite the default ENTRYPOINT of the image
-e, –env list Set environment variables (default [])
–env-file list Read in a file of environment variables (default [])
–expose list Expose a port or a range of ports (default [])
–group-add list Add additional groups to join (default [])
–health-cmd string Command to run to check health
–health-interval duration Time between running the check (ns|us|ms|s|m|h) (default 0s)
–health-retries int Consecutive failures needed to report unhealthy
–health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)
–help Print usage
-h, –hostname string Container host name
–init Run an init inside the container that forwards signals and reaps processes
–init-path string Path to the docker-init binary
-i, –interactive Keep STDIN open even if not attached
–io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only)
–io-maxiops uint Maximum IOps limit for the system drive (Windows only)
–ip string Container IPv4 address (e.g. 172.30.100.104)
–ip6 string Container IPv6 address (e.g. 2001:db8::33)
–ipc string IPC namespace to use
–isolation string Container isolation technology
–kernel-memory string Kernel memory limit
-l, –label list Set meta data on a container (default [])
–label-file list Read in a line delimited file of labels (default [])
–link list Add link to another container (default [])
–link-local-ip list Container IPv4/IPv6 link-local addresses (default [])
–log-driver string Logging driver for the container
–log-opt list Log driver options (default [])
–mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33)
-m, –memory string Memory limit
–memory-reservation string Memory soft limit
–memory-swap string Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap
–memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
–name string Assign a name to the container
–network string Connect a container to a network (default “default”)
–network-alias list Add network-scoped alias for the container (default [])
–no-healthcheck Disable any container-specified HEALTHCHECK
–oom-kill-disable Disable OOM Killer
–oom-score-adj int Tune host’s OOM preferences (-1000 to 1000)
–pid string PID namespace to use
–pids-limit int Tune container pids limit (set -1 for unlimited)
–privileged Give extended privileges to this container
-p, –publish list Publish a container’s port(s) to the host (default [])
-P, –publish-all Publish all exposed ports to random ports
–read-only Mount the container’s root filesystem as read only
–restart string Restart policy to apply when a container exits (default “no”)
–rm Automatically remove the container when it exits
–runtime string Runtime to use for this container
–security-opt list Security Options (default [])
–shm-size string Size of /dev/shm, default value is 64MB
–sig-proxy Proxy received signals to the process (default true)
–stop-signal string Signal to stop a container, SIGTERM by default (default “SIGTERM”)
–stop-timeout int Timeout (in seconds) to stop a container
–storage-opt list Storage driver options for the container (default [])
–sysctl map Sysctl options (default map[])
–tmpfs list Mount a tmpfs directory (default [])
-t, –tty Allocate a pseudo-TTY
–ulimit ulimit Ulimit options (default [])
-u, –user string Username or UID (format: <name|uid>[:<group|gid>])
–userns string User namespace to use
–uts string UTS namespace to use
-v, –volume list Bind mount a volume (default [])
–volume-driver string Optional volume driver for the container
–volumes-from list Mount volumes from the specified container(s) (default [])
-w, –workdir string Working directory inside the container

[root@docker ~]# docker rm e79851f09b67
e79851f09b67
[root@docker ~]# docker rm a9d19d94ea1c
a9d19d94ea1c
[root@docker ~]# docker rm b5dfe72d1fdf
b5dfe72d1fdf
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67c45ff0e1b1 ubuntu “/bin/bash” 3 minutes ago Exited (0) 2 minutes ago festive_darwin

[root@docker ~]# docker start 67c45
67c45
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67c45ff0e1b1 ubuntu “/bin/bash” 3 minutes ago Up 4 seconds festive_darwin

[root@docker ~]# docker inspect 67c45ff0e1b1
[
{
“Id”: “67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741”,
“Created”: “2017-01-21T14:42:10.554661738Z”,
“Path”: “/bin/bash”,
“Args”: [],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 1793,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2017-01-21T14:45:57.069581289Z”,
“FinishedAt”: “2017-01-21T14:42:33.560943513Z”
},
“Image”: “sha256:f49eec89601e8484026a8ed97be00f14db75339925fad17b440976cffcbfb88a”,
“ResolvConfPath”: “/var/lib/docker/containers/67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741/hostname”,
“HostsPath”: “/var/lib/docker/containers/67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741/hosts”,
“LogPath”: “/var/lib/docker/containers/67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741/67c45ff0e1b14203a497113b17e80e6a7f815b4a9450f168387c25689c02e741-json.log”,
“Name”: “/festive_darwin”,
“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/c4b89195054401e1477c8d79c61f392932d4c4e8cfc9e4a8923071efaff9f7e5/root”,
“MergedDir”: “/var/lib/docker/overlay/4225dc62b9cbb3c6ed61f7b9ea90b6b65bdfd91971589f81a92dd5c1096a9262/merged”,
“UpperDir”: “/var/lib/docker/overlay/4225dc62b9cbb3c6ed61f7b9ea90b6b65bdfd91971589f81a92dd5c1096a9262/upper”,
“WorkDir”: “/var/lib/docker/overlay/4225dc62b9cbb3c6ed61f7b9ea90b6b65bdfd91971589f81a92dd5c1096a9262/work”
}
},
“Mounts”: [],
“Config”: {
“Hostname”: “67c45ff0e1b1”,
“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”
],
“Image”: “ubuntu”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “0717b7f2c22a2e754a61c669819b9a10ff16f55fea22f6c3ea906ec75de01223”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {},
“SandboxKey”: “/var/run/docker/netns/0717b7f2c22a”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “4d517256871d3903e19f1da86245baba083ea3756da4c8bcbdb9b879e5b8a45c”,
“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”: “6b8af7369301a5480400d484f921f850d129462ad29b0232d0adc1deaa3fef82”,
“EndpointID”: “4d517256871d3903e19f1da86245baba083ea3756da4c8bcbdb9b879e5b8a45c”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”
}
}
}
}
]

——————————

[root@docker ~]# docker logs 67c45ff0e1b1
root@67c45ff0e1b1:/#
root@67c45ff0e1b1:/#
root@67c45ff0e1b1:/# exit

[root@docker ~]# docker run -p 8000:80 atbaker/nginx-example
Unable to find image ‘atbaker/nginx-example:latest’ locally
latest: Pulling from atbaker/nginx-example
a3ed95caeb02: Pull complete
153220a76b6c: Pull complete
d997e52f6230: Pull complete
25a2529dea4d: Pull complete
9bc1d4cc084a: Pull complete
6670d413bde3: Pull complete
d03059a5bb1f: Pull complete
b3ca04362b66: Pull complete
4895491f8bb6: Pull complete
Digest: sha256:43641d890cdaff2f0f4091e295be30af7067da4be8c559fe4cb1248a2bc3352b
Status: Downloaded newer image for atbaker/nginx-example:latest
The nginx server is running

[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f6e639915e56 atbaker/nginx-example “/command_wrapper.sh” About a minute ago Exited (0) 18 seconds ago cranky_curie
67c45ff0e1b1 ubuntu “/bin/bash” 9 minutes ago Up 5 minutes festive_darwin
[root@docker ~]# docker start f6e639915e56
f6e639915e56

[root@docker ~]# curl -I 172.17.0.3:80
HTTP/1.1 200 OK
Server: nginx/1.7.11
Date: Sat, 21 Jan 2017 14:53:14 GMT
Content-Type: text/html
Content-Length: 14974
Last-Modified: Mon, 06 Apr 2015 19:38:30 GMT
Connection: keep-alive
ETag: “5522e0b6-3a7e”
Accept-Ranges: bytes

docker1.png

[root@docker ~]# curl -I localhost:8000
HTTP/1.1 200 OK
Server: nginx/1.7.11
Date: Sat, 21 Jan 2017 15:05:04 GMT
Content-Type: text/html
Content-Length: 14974
Last-Modified: Mon, 06 Apr 2015 19:38:30 GMT
Connection: keep-alive
ETag: “5522e0b6-3a7e”
Accept-Ranges: bytes

[root@docker ~]# curl -I 172.17.0.3:80
HTTP/1.1 200 OK
Server: nginx/1.7.11
Date: Sat, 21 Jan 2017 15:14:05 GMT
Content-Type: text/html
Content-Length: 14974
Last-Modified: Mon, 06 Apr 2015 19:38:30 GMT
Connection: keep-alive
ETag: “5522e0b6-3a7e”
Accept-Ranges: bytes

[root@docker ~]# docker logs f6e639915e56
The nginx server is running
The nginx server is running
172.17.0.1 – – [21/Jan/2017:14:53:14 +0000] “HEAD / HTTP/1.1” 200 0 “-” “curl/7.29.0” “-”
183.82.220.31 – – [21/Jan/2017:14:56:43 +0000] “GET / HTTP/1.1” 200 14974 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36” “-”
183.82.220.31 – – [21/Jan/2017:14:56:44 +0000] “GET /favicon.ico HTTP/1.1” 404 571 “http://104.198.143.3:8000/&#8221; “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36” “-”
2017/01/21 14:56:44 [error] 5#0: *2 open() “/usr/share/nginx/html/favicon.ico” failed (2: No such file or directory), client: 183.82.220.31, server: localhost, request: “GET /favicon.ico HTTP/1.1”, host: “104.198.143.3:8000”, referrer: “http://104.198.143.3:8000/&#8221;
172.17.0.1 – – [21/Jan/2017:15:04:56 +0000] “GET / HTTP/1.1” 200 14974 “-” “curl/7.29.0” “-”
172.17.0.1 – – [21/Jan/2017:15:05:04 +0000] “HEAD / HTTP/1.1” 200 0 “-” “curl/7.29.0” “-”

[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe84e98225a3 atbaker/nginx-example “–name nginx” About a minute ago Created nervous_poincare
a203a8dca646 atbaker/nginx-example “/command_wrapper.sh” 3 minutes ago Exited (0) 3 minutes ago myxweb
ab925848d4e9 atbaker/nginx-example “/command_wrapper.sh” 25 minutes ago Created nginxweb
67c45ff0e1b1 ubuntu “/bin/bash” 38 minutes ago Up 34 minutes festive_darwin
[root@docker ~]# docker rm -f $(docker ps -aq)
fe84e98225a3
a203a8dca646
ab925848d4e9
67c45ff0e1b1
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

========================================================

[root@docker ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 5114 [OK]

[root@docker ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
5040bd298390: Pull complete
d7a91cdb22f0: Pull complete
9cac4850e5df: Pull complete
Digest: sha256:33ff28a2763feccc1e1071a97960b7fef714d6e17e2d0ff573b74825d0049303
Status: Downloaded newer image for nginx:latest

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest f49eec89601e 18 hours ago 129 MB
nginx latest a39777a1a4a6 3 days ago 182 MB
busybox latest 7968321274dc 7 days ago 1.11 MB
atbaker/nginx-example latest 93db65d92319 21 months ago 93.4 MB

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0300571159a nginx “/bin/bash” 24 minutes ago Up 15 minutes 80/tcp, 443/tcp kickass_hawking

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

[root@docker ~]# docker run -it nginx /bin/bash
root@d0300571159a:/#

root@d0300571159a:/# cat /etc/nginx/nginx.conf

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

root@ce23ca2f19a2:/# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}

root@ce23ca2f19a2:/# cat /usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=”http://nginx.org/”>nginx.org</a&gt;.<br/>
Commercial support is available at
<a href=”http://nginx.com/”>nginx.com</a&gt;.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

—————–
root@d0300571159a:/# cat /etc/issue
Debian GNU/Linux 8 \n \l

root@d0300571159a:/# ls -l
total 16
drwxr-xr-x. 2 root root 4096 Jan 21 15:39 bin
drwxr-xr-x. 2 root root 6 Dec 28 17:42 boot
drwxr-xr-x. 5 root root 360 Jan 21 15:45 dev
drwxr-xr-x. 1 root root 62 Jan 21 15:45 etc
drwxr-xr-x. 2 root root 6 Dec 28 17:42 home
drwxr-xr-x. 9 root root 4096 Jan 21 15:39 lib
drwxr-xr-x. 2 root root 33 Jan 21 15:39 lib64
drwxr-xr-x. 2 root root 6 Jan 16 18:02 media
drwxr-xr-x. 2 root root 6 Jan 16 18:02 mnt
drwxr-xr-x. 2 root root 6 Jan 16 18:02 opt
dr-xr-xr-x. 99 root root 0 Jan 21 15:45 proc
drwx——. 2 root root 35 Jan 21 15:39 root
drwxr-xr-x. 3 root root 28 Jan 21 15:39 run
drwxr-xr-x. 2 root root 4096 Jan 21 15:39 sbin
drwxr-xr-x. 2 root root 6 Jan 16 18:02 srv
dr-xr-xr-x. 13 root root 0 Jan 21 14:32 sys
drwxrwxrwt. 2 root root 6 Jan 17 18:39 tmp
drwxr-xr-x. 10 root root 97 Jan 21 15:39 usr
drwxr-xr-x. 11 root root 4096 Jan 17 18:39 var

root@d0300571159a:/# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

root@d0300571159a:/# service nginx status
[FAIL] nginx is not running … failed!
root@d0300571159a:/# service nginx start
root@d0300571159a:/# service nginx status
[ ok ] nginx is running.

[root@docker ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0300571159a nginx “/bin/bash” 9 minutes ago Exited (100) 4 minutes ago kickass_hawking

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0300571159a nginx “/bin/bash” 9 minutes ago Up 11 seconds 80/tcp, 443/tcp kickass_hawking
root@ce23ca2f19a2:/# curl -I localhost
127.0.0.1 – – [21/Jan/2017:16:03:02 +0000] “HEAD / HTTP/1.1” 200 0 “-” “curl/7.38.0” “-”
HTTP/1.1 200 OK
Server: nginx/1.11.8
Date: Sat, 21 Jan 2017 16:03:02 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 27 Dec 2016 14:23:08 GMT
Connection: keep-alive
ETag: “5862794c-264”
Accept-Ranges: bytes

root@ce23ca2f19a2:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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
34: eth0@if35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:3/64 scope link
valid_lft forever preferred_lft forever
root@ce23ca2f19a2:/# curl -I 172.17.0.3:80
172.17.0.3 – – [21/Jan/2017:16:03:42 +0000] “HEAD / HTTP/1.1” 200 0 “-” “curl/7.38.0” “-”
HTTP/1.1 200 OK
Server: nginx/1.11.8
Date: Sat, 21 Jan 2017 16:03:42 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 27 Dec 2016 14:23:08 GMT
Connection: keep-alive
ETag: “5862794c-264”
Accept-Ranges: bytes

[root@docker ~]# docker run -p 8000:80 nginx
183.82.220.31 – – [21/Jan/2017:16:05:01 +0000] “GET / HTTP/1.1” 200 612 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36” “-”
183.82.220.31 – – [21/Jan/2017:16:05:44 +0000] “GET / HTTP/1.1” 304 0 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36” “-”

docker2.png

[root@docker ~]# docker run -d -p 8000:80 nginx
7c45fa2e319571590cf78ede8a181d5e0da4c86ee3c0f63a9a098db6eee45b6c

 

Advertisements

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