Docker基礎篇11:Compose部署tomcat及mysql
阿新 • • 發佈:2018-12-21
1、compose不是tomcat容器
1、獲取映象
[[email protected] /]# docker pull tomcat
2、建立目錄
[[email protected] /]# mkdir /opt/docker/tomcat -p
[[email protected] /]#cd /opt/docker/tomcat
[[email protected] tomcat]# mkdir -p /opt/docker/tomcat/webapps
3、yaml檔案
[[email protected] /]#cd /opt/docker/tomcat [
[email protected] tomcat]# vim docker-compose.yml version: '3' services: tomcat: restart: always image: tomcat container_name: tomcat ports: - 8080:8080 volumes: - /opt/docker/tomcat/webapps/test:/usr/local/tomcat/webapps/test environment: TZ: Asia/Shanghai
4、前臺啟動
[[email protected] tomcat]# docker-compose -f docker-compose.yml up
2、compose部署mysql
1、獲取mysql映象
[[email protected] ~]# docker pull mysql
2、建立目錄
[[email protected] ~]# mkdir -p /opt/docker/mysql/data
[[email protected] ~]# cd /opt/docker/mysql/
3、yaml檔案
[[email protected] ~]# cd /opt/docker/mysql/
[[email protected] mysql]#vim docker-compose.yml
version: '3'
services:
mysql:
restart: always
image: mysql
container_name: mysql
ports:
- 3307:3307
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DI
VISION_BY_ZERO"
volumes:
- /opt/docker/mysql/data:/var/lib/mysql
4、後臺啟動
[[email protected] mysql]# docker-compose -f docker-compose.yml up -d
[[email protected] ~]# firewall-cmd --permanent --add-port=3306/tcp