现在docker容器技术非常热门,它可以实现进程级的虚拟化,极大的节省资源,更重要的是,用它来安装软件极其方便,很多复杂依赖包问题都不复存在,之前给PostgreSQL安装PostGIS扩展特别费劲,现在直接下载镜像启动就OK了,加上docker-machine和docker swarm集群技术以及docker-compose服务编排技术,用起来真的是非常舒服,然后加上k8s的容器编排技术,可以很快的实现一个云原生集群,它正在行业内刮起一阵炫风。
删除旧版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装
sudo yum install docker-ce docker-ce-cli containerd.io
给镜像仓库加一个阿里的加速器
vim /etc/docker/daemon.sjon
{
"registry-mirrors": ["https://nvqqgptz.mirror.aliyuncs.com"]
}
:x
启动
sudo systemctl start docker
sudo service docker restart
测试
sudo docker run hello-world
查看docke进程
docker ps
docker --version docker version docker info
查看docker镜像
docker image ls
查找镜像
docker search mongo
创建镜像
docker build --tag=friendlyhello .
docker image ls
运行镜像
docker run -p 4000:80 friendlyhello
docker stop id
docker start id
安装ES
docker pull elasticsearch:7.4.0
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.4.3
docker pull kibana
docker run --name kibana -e ELASTICSEARCH_URL=http://192.168.1.1:9200 -p 5601:5601 -d 388661dcd03e
安装pistgres
docker pull postgres:11.5
docker run --name postgres1 -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:11.5
或者安装postgis
docker pull kartoza/postgis:11.0-2.5
docker run -d --name postgis --restart always -e POSTGRES_USER=postgis -e POSTGRES_PASS='postgis' -e ALLOW_IP_RANGE=0.0.0.0/0 -v /docker_root/postgresql11-docker:/var/lib/postgresql -v /4T/tmp:/tmp/tmp -p 55433:5432 -t kartoza/postgis
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION postgis_tiger_geocoder;
安装mondodb
dpcler pull mongo
docker run -p 27017:27017 -v <LocalDirectoryPath>:/data/db --name docker_mongodb -d mongo
docker集群swarm以及编排docker-compse
docker swarm init
docker swarm join-token manager 查看token
docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.198.142:2377 加入集群
ocker swarm leave --force 强行离开
docker node ls 查看swarm集群结点
docker service ls 查看服务
docker compons安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
./install.sh
zk集群配置zoo-cluster.yml
version: '3.1'
services:
zoo1:
image: zookeeper:3.5.6
restart: always
hostname: zoo1
container_name: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper:3.5.6
restart: always
hostname: zoo2
container_name: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper:3.5.6
restart: always
hostname: zoo3
container_name: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
启动
docker stack deploy -c zoo-cluster.yml zoo-cluster //swarm编排服务
docker ps 查看进程