docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx256m" elasticsearch
/// ES_JAVA_OPTS:似乎可以随便命名
docker rm $(docker ps -aq) 删除所有容器,必要时加 -f 强制删除
docker rmi $(docker images -aq) 删除所有镜像
docker stats 074adc0228f8 查看容器的CPU使用情况
docker run -d -p 8088:9000 \--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer docker的可视化界面
docker exec -it 21c4ea23b673 /bin/bash 进入容器
docker volume ls 查看卷
docker inspect 750927e3bcd1 查看容器信息
docker run -d -p 90:80 -v nginx:/opt/nginx nginx 具名挂载
docker run -d -p 90:80 -v /opt/nginx nginx 匿名挂载
docker run -d -p 90:80 -v /home/nginx:/opt/nginx nginx 指定目录挂载 推荐
touch dockerfile 新建文件
docker run -it --name centos01 test/centos
docker run -it --name centos02 --volumes-from centos01 test/centos
docker build -f mydockerfile-centos -t mycentos . 构建镜像
docker build -t mytomcat . 构建镜像文件为官方文件名:Dockerfile 可以简写
docker images 与history搭配使用
docker history 2622e6cca7eb 查看镜像构建过程
docker tag 655720e12264 lvym777/tomcat:1.0 lvym777是DockerHub账号
docker push lvym777/tomcat:1.0
docker save -o test.tar cd645f5a4769 将镜像cd645f5a4769 生成test.tar/zip/GZ等
docker load -i test.zip/tar/GZ 导入镜像
docker run -d -P tomcat 随机分配端口
docker run -d -p tomcat 报错
docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet 自定义网络
-----------------------一般这样命名桥接-----子网掩码 /16表示可以有65535个----网关一般如此--网络名
--------------------------------------------------/24表示可以有255个 --------------------------
docker network ls 查询网络列表
docker network inspect mynet 查看网络详情
docker run -d -P --name tomcat-net01 --net mynet tomcat 将容器加入自己定义的网络
docker run -d -P --name tomcat-net02 --net mynet tomcat
docker network inspect mynet
|
|
docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet
[root@lvym ~]# docker network connect mynet tomcat01
[root@lvym ~]# docker exec -it tomcat01 ping tomcat-net01
PING tomcat-net01 (192.168.0.2) 56(84) bytes of data.
64 bytes from tomcat-net01.mynet (192.168.0.2): icmp_seq=1 ttl=64 time=0.099 ms
64 bytes from tomcat-net01.mynet (192.168.0.2): icmp_seq=2 ttl=64 time=0.174 ms
64 bytes from tomcat-net01.mynet (192.168.0.2): icmp_seq=3 ttl=64 time=0.162 ms
[root@lvym ~]# docker exec -it tomcat-net01 ping tomcat01
PING tomcat01 (192.168.0.4) 56(84) bytes of data.
64 bytes from tomcat01.mynet (192.168.0.4): icmp_seq=1 ttl=64 time=0.084 ms
64 bytes from tomcat01.mynet (192.168.0.4): icmp_seq=2 ttl=64 time=0.154 ms
64 bytes from tomcat01.mynet (192.168.0.4): icmp_seq=3 ttl=64 time=0.054 ms
64 bytes from tomcat01.mynet (192.168.0.4): icmp_seq=4 ttl=64 time=0.071 ms
不同网段是不可以相互通信,tomcat01在 docker默认的网卡docker0中,tomcat-net01在自定义的网卡中,他们是不能相互通信,
通过docker network connect **** 命令把tomcat01加入到自定义的网卡,这样tomcat01在docker0,自定义的网卡,里都有IP
----------------------------------DockerCompose-------------------------
安装
yum -y install epel-release
yum -y install python-pip
pip install--upgrade pip
pip install docker-compose
docker-compose version
---------------------redis三主三从---------------------------------------------------------------
docker network create redis --subnet 172.38.0.0/16
利用脚本写六个配置文件
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 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
拉取并启动redis
docker run -p 6371:6379 -p 16371:13679 --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 172.38.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6372:6379 -p 16372:13679 --name redis-2 \
-v /mydata/redis/node-2/data:/data \
-v /mydata/redis/node-2/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.12 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
........
或
docker run -p 637${port}:6379 -p 1637${port}:13679 --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 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf; \
查看启动
[root@lvym ~]# docker ps
CONTAINER
ID IMAGE COMMAND
CREATED STATUS
PORTS NAMES
eec266e38510
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" 3 seconds ago
Up 2 seconds 0.0.0.0:6376->6379/tcp,
0.0.0.0:16376->13679/tcp redis-6
b05e247481ac
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" 35 seconds ago
Up 35 seconds 0.0.0.0:6375->6379/tcp,
0.0.0.0:16375->13679/tcp redis-5
2911e0e1c29d
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" About a minute ago
Up About a minute 0.0.0.0:6374->6379/tcp,
0.0.0.0:16374->13679/tcp redis-4
d2de98b48e8a
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" About a minute ago
Up About a minute 0.0.0.0:6373->6379/tcp,
0.0.0.0:16373->13679/tcp redis-3
0c8717cf691a
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" 3 minutes ago
Up 3 minutes 0.0.0.0:6372->6379/tcp,
0.0.0.0:16372->13679/tcp redis-2
a4fc26eb694e
redis:5.0.9-alpine3.11 "docker-entrypoint.s…" 4 minutes ago
Up 4 minutes 0.0.0.0:6371->6379/tcp,
0.0.0.0:16371->13679/tcp redis-1
进入容器
[root@lvym ~]# docker exec -it redis-1 /bin/sh
/data # ls
appendonly.aof nodes.conf
配置集群
/data # redis-cli
--cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379
172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 172.38.0.15:6379 to 172.38.0.11:6379
Adding replica 172.38.0.16:6379 to 172.38.0.12:6379
Adding replica 172.38.0.14:6379 to 172.38.0.13:6379
M: a792a6c9ee085b880d4721f176d20a14dc96d93c 172.38.0.11:6379
slots:[0-5460] (5461 slots) master
M: 0cbdb29c2e70dd460fa0eb303d9f9540ad8abd9e 172.38.0.12:6379
slots:[5461-10922] (5462 slots) master
M: aa2fda8fa96ecbff1ab9da3ceea757f68c24a542 172.38.0.13:6379
slots:[10923-16383] (5461 slots) master
S: 4a01710d60dfdc2a0e301ddac5e6e6daf8b45a5f 172.38.0.14:6379
replicates aa2fda8fa96ecbff1ab9da3ceea757f68c24a542
S: 20fa296ea250b1e5080c8deec20c71a55dafd273 172.38.0.15:6379
replicates a792a6c9ee085b880d4721f176d20a14dc96d93c
S: 7997346a77f8f4d0bbc05585480f1da27e0d81b0 172.38.0.16:6379
replicates 0cbdb29c2e70dd460fa0eb303d9f9540ad8abd9e
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
............
登录集群
[OK] All 16384 slots covered.
/data # redis-cli -c
127.0.0.1:6379> cluster nodes
4a01710d60dfdc2a0e301ddac5e6e6daf8b45a5f
172.38.0.14:6379@16379 slave aa2fda8fa96ecbff1ab9da3ceea757f68c24a542 0
1593489128518 4 connected
0cbdb29c2e70dd460fa0eb303d9f9540ad8abd9e 172.38.0.12:6379@16379 master - 0 1593489128000 2 connected 5461-10922
7997346a77f8f4d0bbc05585480f1da27e0d81b0
172.38.0.16:6379@16379 slave 0cbdb29c2e70dd460fa0eb303d9f9540ad8abd9e 0
1593489128926 6 connected
20fa296ea250b1e5080c8deec20c71a55dafd273
172.38.0.15:6379@16379 slave a792a6c9ee085b880d4721f176d20a14dc96d93c 0
1593489128518 5 connected
a792a6c9ee085b880d4721f176d20a14dc96d93c 172.38.0.11:6379@16379 myself,master - 0 1593489128000 1 connected 0-5460
aa2fda8fa96ecbff1ab9da3ceea757f68c24a542 172.38.0.13:6379@16379 master - 0 1593489129941 3 connected 10923-16383
........
标签:小用,--,0.0,redis,6379,172.38,Docker,docker From: https://blog.51cto.com/u_16253752/8346064