docker总结
1.安装docker
//获取最新版本的 Docker 安装包,默认自己安装和启动
wget -qO- https://get.docker.com/ | sh
2.镜像加速(可选),不做下载镜像速度慢
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://4e70ba5d.m.daocloud.io
3.重启docker
service docker restart或者systemctl restart docker
4.docker基本的相关指令,
以tomcat为例,tomcat也可以替换成容器id的前4位数字做为唯一标识
//docker hub上搜索镜像
docker search tomcat
//拉镜像
docker pull tomcat
//启动容器
docker run --name tomcat-test2 -p 7070:8080 -v /home/emg-dev-02/webapps/emap-test:/usr/local/tomcat/webapps/ -d tomcat
//交互模式进入容器
docker exec -it tomcat /bin/bash
//看容器日志
docker logs tomcat
//启动容器
docker start tomcat
//关闭容器
docker stop tomcat
//删除容器
docker rm tomcat
//删除镜像
docker rmi tomcat
//查看所有的容器
docker ps -a
//查看正在运行的容器
docker ps
5.Dockerfile文件的编写
需要了解几个关键词(FROM,ADD,CMD)即可,需要用到别的,自己百度即可
例如:启动springboot的jar包,同时内部调用so文件,如下:
FROM openjdk:8
ADD emap-wgtochina-0.0.1-SNAPSHOT.jar emap-wgtochina.jar
ADD libwgtochina.so libwgtochina.so
CMD java -jar emap-wgtochina.jar
例如:加载war包,启动tomcat,如下:
FROM tomcat
ADD emap-redirect.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
6.docker-compose的使用,我的理解docker-compose就是启动容器的脚本,也就是偷懒工具
6.1.安装docker-compose工具
apt update
apt install docker-compose或者pip install docker-compose
6.2 查看docker-compose版本
docker-compose --version
6.3 docker-compose.yml文件格式
具体关键词的意思请看:
https://blog.csdn.net/qq_36148847/article/details/79427878
我这列几个例子
redis的:
version: '3'
services:
redis:
container_name: redis
image: "registry.emg.local/tools/redis:5.0.3"
ports:
- "6378:6379"
volumes:
- /home/emg/docker-compose/redis/redis.conf:/etc/redis/redis.conf
command: redis-server /etc/redis/redis.conf
mongo的:
version: '3'
services:
mongo:
container_name: mongo
image: "registry.emg.local/tools/mongo:4.0.6"
ports:
- "27018:27017"
volumes:
- /home/emg/docker-compose/mongo/data:/data/db
command: ["mongod", "--bind_ip","0.0.0.0"]
restart: always
postgres:
version: '3'
services:
postgres:
container_name: postgres
image: "registry.emg.local/tools/postgres:9.6.12"
privileged: true
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=${pwd}
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- /mnt/postgres/data:/var/lib/postgresql/data/pgdata
restart: always
kafka的
version: '3'
services:
zookeeper:
container_name: zookeeper
image: "registry.emg.local/tools/zookeeper:latest"
ports:
- "2182:2181"
restart: always
kafka:
container_name: kafka
image: "registry.emg.local/tools/kafka:latest"
ports:
- "9093:9092"
depends_on:
- zookeeper
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.41.88
KAFKA_ZOOKEEPER_CONNECT: 192.168.41.88:2182
volumes:
- /var/run/docker.sock:/var/run/docker.sock
springboot的jar包
version: '3'
services:
convert:
container_name: convert
image: "registry.emg.local/traffic/emap-wgtochina:v2"
ports:
- "9040:9040"
volumes:
- /home/emg/docker-compose/wgtochina:/home
restart: always
deploy:
replicas: 2
等等。。
7.docker swarm的部署方式
详细介绍请看:
https://www.cnblogs.com/drawnkid/p/8487337.html
我这里说下几个关键指令
//创建一个Swarm集群 主机ip即可
docker swarm init --advertise-addr 192.168.99.1
//来查看当前swarm集群的状态
docker info
//将节点加入到swarm集群中
docker swarm join --token SWMTKN-1-2bgkinnbc0rmlj6kpotyrlj0uz51l2ikinttsk960dxro558x4-6zajfnahtv9ye39momddh5kru 192.168.99.1:2377
//查看集群节点情况
docker node ls
//如果忘记token,则查找
docker swarm join-token worker
//根据docker-compose.yml文件,启动单节点多个实例
docker stack deploy -c docker-compose.yml stack-demo
//查看docker servie列表
docker service ls
目前总结到这里,以后会有补充。