设为首页 收藏本站
查看: 534|回复: 0

[经验分享] CentOS7 部署docker

[复制链接]

尚未签到

发表于 2018-4-20 11:44:40 | 显示全部楼层 |阅读模式
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     &quot;bash&quot;              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
                        &quot;HostIp&quot;: &quot;&quot;,
            &quot;IpcMode&quot;: &quot;&quot;,
            &quot;LinkLocalIPv6Address&quot;: &quot;&quot;,
            &quot;LinkLocalIPv6PrefixLen&quot;: 0,
                        &quot;HostIp&quot;: &quot;0.0.0.0&quot;,
            &quot;SecondaryIPAddresses&quot;: null,
            &quot;SecondaryIPv6Addresses&quot;: null,
            &quot;GlobalIPv6Address&quot;: &quot;&quot;,
            &quot;GlobalIPv6PrefixLen&quot;: 0,
            &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,
            &quot;IPPrefixLen&quot;: 16,
            &quot;IPv6Gateway&quot;: &quot;&quot;,
                    &quot;IPAMConfig&quot;: null,
                    &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,
                    &quot;IPPrefixLen&quot;: 16,
                    &quot;IPv6Gateway&quot;: &quot;&quot;,
                    &quot;GlobalIPv6Address&quot;: &quot;&quot;,
                    &quot;GlobalIPv6PrefixLen&quot;: 0,
[root@Docker ~]#
6.浏览器访问测试:
http://IP:8080
DSC0000.jpg

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 &quot;<h1>www.hello.com</h1>&quot;> index.html
root@0a9db4be695b:/usr/share/nginx/html# exit
exit
[root@Docker ~]#
8.浏览器访问测试:
http://IP:8080
DSC0001.jpg

9.强制删除所有的虚拟机
[root@Docker ~]# docker rm -f `docker ps -aq`

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-449614-1-1.html 上篇帖子: centos下简单的优化内存的方法 下篇帖子: centos 脚本基础练习1
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表