Docker环境安装及配置

9月 20th, 2016
1.实验环境:
1.1 虚拟机:VirtualBox 4.3;
1.2 操作系统:CentOS7.2/3.10.0-327.el7.x86_64;
1.3 服务器名:docker.htsec.com;
1.4 IP:192.168.10.100(内网IP)/10.0.2.15(外网IP);
2.下载docker的rpm包,并配置YUM源:
2.1 下载docker的yum包:wget -S -c -r -np -L https://yum.dockerproject.org/repo/main/centos/7/;
2.2 修改目录:
mkdir -p /tools/docker/centos7
mv yum.dockerproject.org/repo/main/centos/7/* /tools/docker/centos7/
2.3 添加/etc/yum.repos.d/docker.repo文件,配置yum源;
[dockerrepo]
name=Docker Repository
baseurl=file:///tools/docker/centos7
enabled=1
gpgcheck=0
3.添加CentOS操作系统的YUM源:
3.1 挂载光盘并把内容拷贝至/tools/centos72/目录;
3.2 添加/etc/yum.repos.d/centos.repo文件,配置yum源;
[centosrepo]
name=CentOS7 Repository
baseurl=file:///tools/centos72/
enabled=1
gpgcheck=0
3.3 创建yum缓存:
yum clean all
yum makecache
4.安装并启动docker:
4.1 必要条件:Docker必须安装在64位操作系统上,而且内核版本必须大于3.10;(CentOS7的内核版本最小是3.10,使用uname -r命令查看)
4.2 使用yum安装:如果服务器可以访问外网,则可以直接配置指向官方的YUM源;n在企业内部一般会构建私有的YUM源;
yum update -y
yum install -y docker-engine
4.3 如果直接使用rpm安装的话,需要先解决包依赖;
yum -y install libcgroup libtool-ltdl policycoreutils-python
rpm -ivh docker-engine-selinux-1.11.2-1.el7.centos.noarch.rpm
rpm -ivh docker-engine-1.11.2-1.el7.centos.x86_64.rpm
4.4 启动docker;
service docker start 或者 /bin/systemctl start  docker.service
4.5 配置开机启动;
chkconfig docker on 或者 systemctl enable docker.service
5.验证docker是否安装成功;
[root@docker ~]# docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.
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 Hub account:
 https://hub.docker.com
For more examples and ideas, visit:
问题:WARNING: IPv4 forwarding is disabled. Networking will not work.
解决办法:
1.在/usr/lib/sysctl.d/00-system.conf配置文件中添加代码;
net.ipv4.ip_forward=1
2.重启network服务;
systemctl restart network
3.查看是否修改成功;
sysctl net.ipv4.ip_forward
标签:
目前还没有任何评论.