测试用Docker Swarm环境搭建
系统安装运行需求和建议:
- 一台独立的linux host centos 7.4
- docker 18.06.1-ce版本
- docker swarm自定义网络my-network
docker安装脚本
name=node01
hostnamectl set-hostname $name
#自定义配置主机名称
yum -y install wget vim lrzsz git
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
getenforce
#关闭防火墙,selinux,安装必备常用软件
mkdir -p /soft/ && cd /soft/
yum remove -y docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce.x86_64 --showduplicates | sort -r
#列出可以安装的docker版本
yum -y install docker-ce-18.06.1.ce
#安装指定版本的docker
mkdir -p /lib/systemd/system/docker.service.d
cat > /lib/systemd/system/docker.service.d/docker.conf << 'EOF'
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --default-ulimit nofile=65536
EOF
#--default-ulimit有bug,暂时无法放到/etc/docker/daemon.json里
mkdir -p /etc/docker/
mkdir -p /srv/docker/
cat > /etc/docker/daemon.json << EOF
{
"dns": [
"114.114.114.114",
"8.8.8.8"
],
"data-root": "/srv/docker/",
"hosts": [
"unix:///var/run/docker.sock"
],
"registry-mirrors": [
"https://0sr73mco.mirror.aliyuncs.com"
]
}
EOF
systemctl daemon-reload
systemctl start docker
systemctl enable docker
docker info
docker version
docker swarm安装脚本
docker swarm init
docker node ls
docker node inspect node01 --pretty
#查看docker node节点信息
docker network create --attachable --driver=overlay --subnet=10.17.0.0/16 my-network
docker network ls
#创建docker network网络,名称叫my-network
docker pull nginx
docker service create --replicas 1 --name my-web --network my-network --publish 8888:80 nginx
docker service ls
curl 127.0.0.1:8888
#创建一个docker service create示例
大漠孤烟直
长河落日圆