赞
踩
1、Linux下Docker安装
1)安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
2)安装docker
yum install -y docker
3)启动和关闭docker
启动:systemctl start docker
关闭:systemctl stop docker
2、docker-compose管理容器
下载docker-compose
1)下载依赖
执行命令:
curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
2)给下载目录授予权限
chomod 777 /usr/local/bin/docker-compose
验证docker-compose是否安装成功
docker-compose –v
创建docker-compose.yaml配置文件
1)在root目录下创建一个docker-compose的目录
- cd /root
-
- mkdir docker-compose
- touch docker-compose.yml
添加以下配置:
- version: '3'
-
- services:
-
- mysql:
-
- image: mysql:5.7
-
- privileged: true
-
- ports:
-
- - 3306:3306
-
- environment:
-
- - MYSQL_ROOT_PASSWORD=Testfan#123
-
- volumes:
-
- - /root/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf
-
- - /root/docker/mysql/data:/var/lib/mysql
-
- networks:
-
- - mtx
-
- redis:
-
- image: redis
-
- privileged: true
-
- ports:
-
- - 6379:6379
-
- volumes:
-
- - /root/docker/redis/conf/redis.conf:/etc/redis/redis.conf
-
- networks:
-
- - mtx
-
- command: redis-server /etc/redis/redis.conf
-
- tomcat-pinter-1:
-
- image: tomcat:8.5.0-jre8
-
- privileged: true
-
- ports:
-
- - 8080:8080
-
- volumes:
-
- - /root/docker/tomcat/webapps:/usr/local/tomcat/webapps
-
- networks:
-
- - mtx
-
- depends_on:
-
- - mysql
-
- - redis
-
- tomcat-pinter-2:
-
- image: tomcat:8.5.0-jre8
-
- privileged: true
-
- ports:
-
- - 8090:8080
-
- volumes:
-
- - /root/docker/tomcat/webapps:/usr/local/tomcat/webapps
-
- networks:
-
- - mtx
-
- depends_on:
-
- - mysql
-
- - redis
-
- nginx:
-
- image: nginx
-
- privileged: true
-
- ports:
-
- - 80:80
-
- volumes:
-
- - /root/docker/nginx/conf.d:/etc/nginx/conf.d
-
- - /root/docker/nginx/logs:/var/log/nginx
-
- networks:
-
- - mtx
-
- depends_on:
-
- - tomcat-pinter-1
-
- - tomcat-pinter-2
-
- networks:
-
- mtx:
-
- driver: bridge
2)关闭以前启动的容器
- docker stop 84c4fa341d62
- docker stop 4672429de27b
- docker stop de5032a8efd7
- docker stop 8ddf607e7359
- docker stop 52b94a9fb918
3)在docker-compose.yml同级目录下启动
docker-compose up –d
4)浏览器中检查是否可以访问
5)docker-compose其他命令
后台启动容器:docker-compose up -d [容器名]
停止并删除容器:docker-compose down [容器名]
停止容器:docker-compose stop [容器名]
重启容器:docker-compose restart [容器名]
查看容器:docker-compose ps [容器名]
查看日志:docker-compose logs [容器名]
感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。