Docker 笔记(常用模板)
docker-mongodb
sh
## 下载镜像
docker pull mongo:4.2.6-bionic
## 运行容器,设置映射
docker run --name mongo-4.2.6 -p 27017:27017 -v /data/mongodb/configdb:/data/configdb -v /data/mongodb/db:/data/db -d mongo:4.2.6-bionic
## 如果容器无写文件权限
关闭SELinux
## 进入 mongo shell
docker exec -it mongo-4.2.6 mongo admin
db.createUser({user:'admin',pwd:'admin1357',roles:[{role:'userAdminAnyDatabase',db:'admin'}]});
db.auth('admin', 'admin1357')
exit
## 查看运行的容器信息
docker ps -n 5
## 查看容器的配置信息
docker inspect ID
## 重启容器
docker restart ID
docker-mariadb
sh
docker run -d --name mariadb --restart=always -p 3306:3306 \
-e MARIADB_ROOT_PASSWORD=5POELaFXVfy7 mariadb/server:10.4
docker-GitLab
sh
## 下载镜像
docker pull gitlab/gitlab-ce:12.1.11-ce.0
docker run -d -v /data/gitlab/etc:/etc/gitlab -v /data/gitlab/log:/var/log/gitlab -v /data/gitlab/data:/var/opt/gitlab --name gitlab -p 8887:80 gitlab/gitlab-ce:12.1.11-ce.0
## 如果是从旧服务器迁移,备份/还原需要保持相同版本
## 备份时需要保持gitlab处于正常运行状态,直接执行
gitlab-rake gitlab:backup:create
## 使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1530156812_2018_06_28_10.8.4_gitlab_backup.tar的压缩包
## 在老服务器上将备份文件发送至新服务器的相应目录下
## gitlab恢复
gitlab-ctl stop unicorn ## 停止相关数据连接服务
gitlab-ctl stop sidekiq
chmod 777 /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=1530156812_2018_06_28_10.8.4
gitlab-ctl start ## 启动gitlab
docker-jenkins
参考: https://www.jianshu.com/p/cf2920acf51a
sh
docker run -d --name jenkins -u root -p 11111:8080 --privileged -p 50000:50000 -v /data/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /bin/docker:/bin/docker jenkins/jenkins:lts
映射宿主的 docker 到容器内,这样容器内可以构建 docker。 其中 privileged 使得容器的 root 对宿主具有真正的 root 权限。
jenkins 插件更新加速
sh
cd {你的Jenkins工作目录}/updates #进入更新配置位置
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
docker redis
sh
docker run --name redis -p 6379:6379 -d redis
docker 自定义 xampp
sh
docker run --name xampp-custom -d -v /data/xampp/var:/opt/lampp/var -v /data/xampp/htdocs:/opt/lampp/htdocs -v /data/xampp/logs:/opt/lampp/logs -p 82:81 xampp-custom
docker-compsose 模板
yaml
version: "3"
services:
internal-xampp:
image: xampp-custom
container_name: internal-xampp
ports:
- "81:81"
volumes:
- /data/xampp/var:/opt/lampp/var
- /data/xampp/htdocs:/opt/lampp/htdocs
- /data/xampp/logs:/opt/lampp/logs
networks:
- internal-bridge
internal-nginx:
image: nginx
container_name: internal-nginx
ports:
- "80:80"
volumes:
- /data/nginx/etc/conf.d:/etc/nginx/conf.d
- /data/nginx/html:/usr/share/nginx/html
- /data/nginx/etc/nginx.conf:/etc/nginx/nginx.conf
links:
- internal-xampp:xampp
networks:
- internal-bridge
depends_on:
- internal-xampp
networks:
internal-bridge:
driver: bridge
docker-compose mariadb + zk + kafka
yaml
version: "3"
services:
## mariadb
mariadb-10.4:
image: mariadb/server:10.4
container_name: mariadb-10.4
ports:
- "3306:3306"
volumes:
- /data/mariadb/data:/var/lib/mysql
- /data/mariadb/my.cnf:/etc/mysql/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- bridge
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- zookeeper
networks:
bridge:
driver: bridge
ES 单节点
yaml
version: "2.2"
services:
es01:
image: elasticsearch:7.5.2
container_name: es01
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /home/cyberv/docker/es/data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
networks:
elastic:
driver: bridge
ES 集群
yaml
version: "2.2"
services:
es01:
image: elasticsearch:7.5.2
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /home/cyberv/docker/es/data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: elasticsearch:7.5.2
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /home/cyberv/docker/es/data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: elasticsearch:7.5.2
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /home/cyberv/docker/es/data03:/usr/share/elasticsearch/data
networks:
- elastic
cerebro:
image: lmenezes/cerebro
container_name: cerebro
ports:
- 9000:9000
networks:
- elastic
networks:
elastic:
driver: bridge