运行mysql
root@mysheep:/var/lib/docker# docker run -p 3306:3306 --name mysql -v /usr/local/docker/mysql/conf:/etc/mysql -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql-files -e MYSQL_ROOT_PASSWORD=170201 -d mysql
dc550820366d3e59e9333ad542e9031ee1d96ef50a9a30add5ebae1ee983991d
查看正在运行得容器
root@mysheep:/var/lib/docker# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc550820366d mysql "docker-entrypoint.s…" 5 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
和容器进行交互
root@mysheep:/var/lib/docker# docker exec -it mysql bash
为了可以进行远程连接,需要更改配置,进入mysql
root@dc550820366d:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
进行更改,允许任何IP连接
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码'
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
这样就能在外部进行远程连接
docker compose
https://github.com/docker/compose/releases
进入网址下载docker compose,下载发行版
然后用xftp进行文件传输,然后放入环境中,就可以查看信息
root@mysheep:/usr/bin# docker-compose version
docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
运行tomcat
在。usr/local/docker/下创建tomcat文件夹,进入创建docker-compose.yml文件,进行编写
version: '3'
services:
tomcat:
restart: always
image: tomcat
container_name: tomcat
ports:
- 8080:8080
volumes:
- /usr/local/docker/tomcat/webapps/:/usr/local/tomcat/webapps
environment:
TZ: Asia/Chengdu
然后运行文件
root@mysheep:/usr/local/docker/tomcat# docker-compose up
tomcat启动成功
root@mysheep:/usr/local/docker/tomcat# docker-compose down
Removing tomcat ... done
Removing network tomcat_default
停止tomcat