Centos7 docker安装实例

摘要:安装docker,常用命令

安装docker

yuminstalldocker

1

1

配置国内镜像源(提速)

国内加速源:https://www.daocloud.io/mirror.html#accelerator-doc

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh| sh -s http://0fc8f023.m.daocloud.io

1

1

下载docker镜像

搜索镜像

docker search centos

1

1

[root@cloud CentOS-YUM]# docker search centosINDEX      NAME                                            DESCRIPTION                                    STARS    OFFICIAL  AUTOMATEDdocker.iodocker.io/centos                                The official build of CentOS.2987[OK]      docker.iodocker.io/jdeathe/centos-ssh                    CentOS-66.8x86_64 / CentOS-77.3.1611x8...55[OK]docker.iodocker.io/nimmis/java-centos                    This is docker images of CentOS7with dif...20[OK]docker.iodocker.io/consol/centos-xfce-vnc                Centos container with"headless"VNC sessi...18[OK]docker.iodocker.io/million12/centos-supervisor            Base CentOS-7with supervisord launcher, h...12[OK]docker.iodocker.io/torusware/speedus-centos              Always updated official CentOS docker imag...8

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

下载镜像

docker pull centos:6#下载centos6

1

1

查看镜像

docker images#查看镜像

1

1

启动容器

创建容器实例

[root@cloud~]# docker imagesREPOSITORYTAGIMAGEIDCREATEDSIZEssh-centos6                  latest670e6db182f55days ago497.1MBdocker.io/centos              latest67591570dd293weeks ago191.8MBdocker.io/centos68315978ceaaa9weeks ago194.6MB[root@cloud~]# docker run -i -t --name=centos10  ssh-centos6  /bin/bash    #用镜像ssh-centos6创建容器,设置名称为centos10[root@e308c0493046/]#

1

2

3

4

5

6

7

1

2

3

4

5

6

7

docker命令

# 查看运行中的容器docker ps # 查看所有容器docker ps-a# 退出容器按Ctrl+D 即可退出当前容器【但退出后会停止容器】# 退出不停止容器:组合键:Ctrl+P+Q# 启动容器docker start 容器名或ID# 进入容器docker attach 容器名或ID# 停止容器docker start 容器名或ID# 删除全部容器--慎用docker stop $(docker ps-q)&docker rm $(docker ps-aq)#保存容器,生成镜像docker commit 容器ID 镜像名称

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

docker配置

限制容器资源

#CPU使用0-3总共4个核心,内存1G,--net=none不配置网络(桥接模式是pipework设置网络)dockerrun-itd--net=none--name=centos07--cpuset-cpus="0-3"-m1024M--memory-reservation1024Mcentos6-132.97.8.7-170106_2/bin/bash

1

2

1

2

更改存储目录

#复制docker存储目录rsync -aXS /var/lib/docker/. /home/docker#更改 docker 存储文件目录ln -s  /home/docker  /var/lib/docker

1

2

3

4

5

1

2

3

4

5

设置存储大小

# ubuntu在/etc/default/docker# centos在/etc/sysconfig/docker-storagecat /etc/sysconfig/docker-storageDOCKER_STORAGE_OPTIONS="--storage-opt dm.loopdatasize=2000G --storage-opt dm.loopmetadatasize=10G --storage-opt dm.fs=ext4 --storage-opt dm.basesize=20G"#dm.loopdatasize=2000G是指存放数据的数据库空间为2t,默认是100g#dm.loopmetadatasize=10G是存放Metadata数据空间为10g,默认是2g#dm.fs=ext4是指容器磁盘分区为ext4#dm.basesize=20G是指容器根分区默认为20g,默认是10g

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

docker桥接模式

linux桥接网络配置

[root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-br0[root@localhost network-scripts]# vi ifcfg-eth0//改成这样DEVICE=eth0HWADDR=00:0C:29:06:A2:35TYPE=EthernetUUID=34b706cc-aa46-4be3-91fc-d1f48c301f23ONBOOT=yesBRIDGE=br0NM_CONTROLLED=yesBOOTPROTO=static[root@localhost network-scripts]# vi ifcfg-br0//改成这样DEVICE=br0TYPE=BridgeONBOOT=yesBOOTPROTO=staticIPADDR=192.168.216.131NETMASK=255.255.255.0GATEWAY=192.168.216.2DNS=8.8.8.8

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

重启网卡

service network restart

1

1

设置启动参数

# centos在/etc/sysconfig/docker#其他操作系统请前往下面的网址# https://docs.docker.com/installation/#installationvi /etc/sysconfig/docker #在OPTIONS='--selinux-enabled'这行中修改为OPTIONS='--selinux-enabled -b=br0'即让docker服务启动时使用br0网卡进行桥接

1

2

3

4

1

2

3

4

安装pipework

git clone https://github.com/jpetazzo/pipeworkcp ~/pipework/pipework /usr/local/bin/

1

2

1

2

启动手动设置网络的容器

docker run-itd--net=none--name=centos06--cpuset-cpus="0-3"-m1024M--memory-reservation1024M ssh-centos6/bin/bash

1

1

使用pipework设置IP

pipeworkbr0 centos06132.97.8.6/[email protected]

1

1

进去docker查看IP

dockerattachcentos06ifconfigservice sshd restart#重启ssh

1

2

3

1

2

3

docker开机启动脚本

vi docker_start.sh

1

1

#! /bin/bash# chkconfig: 2345 10 90# description: dockerservice docker startdocker start centos06docker start centos07pipework br0 centos06132.97.8.6/[email protected] br0 centos07132.97.8.7/[email protected]  centos06 service sshd restartdockerexec-i  centos07 service sshd restart

1

2

3

4

5

6

7

8

9

10

11

1

2

3

4

5

6

7

8

9

10

11

1、将脚本移动到/etc/rc.d/init.d目录下mv/home/xy/docker_start.sh/etc/rc.d/init.d2、增加脚本的可执行权限chmod+x/etc/rc.d/init.d/docker_start.sh3、添加脚本到开机自动启动项目中cd/etc/rc.d/init.dchkconfig--add docker_start.shchkconfig docker_start.sh on

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

其他资料

# 5分钟弄懂Docker!http://www.csdn.net/article/2014-07-02/2820497-what%27s-docker# docker操作实例,图文教程http://blog.csdn.net/wuzhilon88/article/details/41621285/

Centos7 docker安装实例_第1张图片

用云栖社区APP,舒服~

原文链接 

你可能感兴趣的:(Centos7 docker安装实例)