1、docker 安装nginx
1、拉取镜像
# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
33847f680f63: Pull complete
dbb907d5159d: Pull complete
8a268f30c42a: Pull complete
b10cf527a02d: Pull complete
c90b090c213b: Pull complete
1f41b2f2bf94: Pull complete
Digest: sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZbp1anm6ub4cms5pa42hkZ ~]# docker image
2、启动
docker run -d --name nginx01 -p 3344:80 nginx
# docker run -d --name nginx01 -p 3344:80 nginx
d698a8dc86c62a4bcf68aa7d4473458ebd3e322dc5b4582a018c64c1a98d11cd
3、测试
curl localhost:3344
# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
2、docker 自定义网络
查看所有网络
#docker network ls
NETWORK ID NAME DRIVER SCOPE
2b6e8d10ea8a bridge bridge local
50f7a20b161c hadoop bridge local
fce741930e53 host host local
44d3abc0f4f0 none null local
网络模式:
bridge 桥接docker默认(自定义网络建议)
host 和宿主机共享网络
container 容器网络互联
启动时,默认适用bridge
创建network 的帮助
--attachable Enable manual container attachment
--aux-address map Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[])
--config-from string The network from which copying the configuration
--config-only Create a configuration only network
-d, --driver string Driver to manage the Network (default “bridge”)
–gateway strings IPv4 or IPv6 Gateway for the master subnet
–ingress Create swarm routing-mesh network
–internal Restrict external access to the network
–ip-range strings Allocate container ip from a sub-range
–ipam-driver string IP Address Management Driver (default “default”)
–ipam-opt map Set IPAM driver specific options (default map[])
–ipv6 Enable IPv6 networking
–label list Set metadata on a network
-o, --opt map Set driver specific options (default map[])
–scope string Control the network’s scope
–subnet strings Subnet in CIDR format that represents a network segment
自定义网络可以使用容器名ping通
1、自定义网络
# docker network create --driver bridge --subnet 192.168.1.0/24 --gateway 192.168.1.1 redis
3、实战:配置redis集群
1、使用脚本编写6个配置文件
shell脚本
for port in $(seq 1 6);\
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat << EOF > /mydata/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 192.168.1.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
#单个启动:
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
-v /mydata/redis/node-1/data:/data \
-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 192.168.1.11 redis redis-server /etc/redis/redis.conf
#多个启动:
for port in $(seq 1 6);\
do
docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \
-v /mydata/redis/node-${port}/data:/data \
-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 192.168.1.1${port} redis redis-server /etc/redis/redis.conf
done
2、构建集群
redis-cli --cluster create 192.168.1.11:6379 192.168.1.12:6379 192.168.1.13:6379 192.168.1.14:6379 192.168.1.15:6379 192.168.1.16:6379 --cluster-replicas 1
成功!