|
1.docker安装
CentOS7
yum install epel-release -y
yum install docker -y
[root@Docker ~]# docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
Go version: go1.8.3
Git commit: 85d7426/1.12.6
Built: Tue Oct 24 15:40:21 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
Go version: go1.8.3
Git commit: 85d7426/1.12.6
Built: Tue Oct 24 15:40:21 2017
OS/Arch: linux/amd64
[root@Docker ~]#
[root@Docker ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.12.6
Storage Driver: devicemapper
Pool Name: docker-253:0-270443527-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 11.8 MB
Data Space Total: 107.4 GB
Data Space Available: 102.8 GB
Metadata Space Used: 581.6 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2015-10-14)
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: host bridge overlay null
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Security Options: seccomp
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 2
Total Memory: 1.954 GiB
Name: localhost.localdomain
ID: 7NNL:RVYC:M6QY:CP2P:5SNV:3N25:U45I:TUWG:Y4NK:7H4R:CN2B:3E67
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Insecure Registries:
127.0.0.0/8
Registries: docker.io (secure)
CentOS6
yum install epel-release -y
yum install lxc libcgroup device-map* -y
yum install docker-io -y
[root@Docker ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
[root@Docker ~]#
[root@Docker ~]# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-253:0-130626-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 305.7 MB
Data Space Total: 107.4 GB
Data Space Available: 11.1 GB
Metadata Space Used: 729.1 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-12-13)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-431.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 1.834 GiB
Name: localhost.localdomain
ID: SKZZ:TYST:LUEG:N66O:364P:7YRG:GQ3W:ODYR:G476:JSHB:I2HF:3A5W
说明:docker 默认的存储驱动类型为devicemapper,docker-ce 默认的存储驱动类型为overlay2。
2.搜索并下载nginx容器
[root@Docker ~]# docker search nginx
[root@Docker ~]# docker pull docker.io/nginx
3.将容器的80端映射到本机的8080
[root@Docker ~]# docker run --name=nginx -itd -p8080:80 docker.io/nginx bash
或者
[root@Docker ~]# docker run --name nginx -itd -p8080:80 docker.io/nginx /bin/bash
或者
[root@Docker ~]# docker run --name=nginx -itd -p8080:80 docker.io/nginx
注:--privileged 给予管理员权限,--restart=always 容器随docker宿主机的启动而启动;CentOS7安装服务器后若使用systemctl工具启动创建容器时需要执行/usr/sbin/init或/sbin/init命令。
4.查看docker容器进程
[root@Docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26ae21c8bddd docker.io/nginx "bash" 5 seconds ago Up 4 seconds 0.0.0.0:8080->80/tcp nginx
5.查看docker容器IP地址
[root@Docker ~]# docker inspect 0a9db4be695b |grep -i ip
"HostIp": "",
"IpcMode": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"HostIp": "0.0.0.0",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@Docker ~]#
6.浏览器访问测试:
http://IP:8080
7.登录进入容器中,更改默认的测试页面内容
[root@Docker ~]# docker exec -it 0a9db4be695b /bin/bash
root@0a9db4be695b:/# cd /usr/share/nginx/html/
root@0a9db4be695b:/usr/share/nginx/html# ls
50x.html index.html
root@0a9db4be695b:/usr/share/nginx/html# echo "<h1>www.hello.com</h1>"> index.html
root@0a9db4be695b:/usr/share/nginx/html# exit
exit
[root@Docker ~]#
8.浏览器访问测试:
http://IP:8080
9.强制删除所有的虚拟机
[root@Docker ~]# docker rm -f `docker ps -aq` |
|
|