1. mysql
Reference: https://hub.docker.com/_/mysql/
1. Download the mysql image
sudo docker pull mysql
2. Start the mysql container
sudo docker run -d -p 3306:3306 --name dbmysql -e MYSQL_ROOT_PASSWORD=password -v /mysql/datadir:/var/lib/mysql -v /mysql/conf:/etc/mysql/conf.d docker.io/mysql:latest -e MYSQL_ROOT_PASSWORD=password : Specify the root password -v /mysql/datadir:/var/lib/mysql : Specify the local storage path of the database. If the system does not close SELinux, it will fail to start because the local directory is not allowed to be mounted to the container. You need to execute chcon -Rt svirt_sandbox_file_t /mysql first /datadir -v /mysql/conf:/etc/mysql/conf.d : Specifies to use a custom mysql configuration file to start the database, such as creating a my-config.cnf in this path vi my-config.cnf [mysqld] port=3306 character-set-server=utf8 wait_timeout=288000 # Link timeout, default is 8 hours, in seconds lower_case_table_names=1 # Do not desensitize case
3. docker-compose method:
go to root user
mkdir -p /docker-compose-dir/mysql
cd /docker-compose-dir/mysql
vi docker-compose.yml
dbmysql: image: docker.io/mysql:latest ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: password volumes: - /mysql/datadir:/var/lib/mysql - /mysql/conf:/etc/mysql/conf.d:ro
[root@centos-linux-agent mysql]# docker-compose up -d Creating mysql_dbmysql_1 [root@centos-linux-agent mysql]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 087f4e32cd29 docker.io/mysql:latest "docker-entrypoint.sh" 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp mysql_dbmysql_1
4. Database script initialization
sudo docker run -it --rm --link=mysql_dbmysql_1:db -v /mysql_sql:/mysql_sql mysql:latest mysql -hdb -uroot -ppassword -Ddbname
Second, tomcat
Reference: https://hub.docker.com/_/tomcat/
Download mirror:
sudo docker pull tomcat
Currently the latest version is 8.0.X, you can find the required tag version of jre+tomcat through the official address above
Start the container:
sudo docker run -d -p 8080:8080 -v /usr/local/tomcat tomcat:latest
View the path where the tomcat directory in the container is mounted to this machine:
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ef993d0f48c1 tomcat:latest "catalina.sh run"22 minutes ago Up9 minutes 0.0.0.0:8080->8080/tcp goofy_blackwell
[{bbc41e0bbc97ae32839e876f291eb60173b6b1fc2867dd11a5381f85a85b8a59 /var/lib/docker/volumes/bbc41e0bbc97ae32839e876f291eb60173b6b1fc2867dd11a5381f85a85b8a59/_data /usr/local/tomcat local true }]
mkdir -p /docker-compose-dir/tomcat
cd /docker-compose-dir/tomcat
vi docker-compose.yml
version: '2' services: db: image: docker.io/mysql:latest volumes: - /mysql/datadir_tomcat:/var/lib/mysql - /mysql/conf:/etc/mysql/conf.d:ro restart: always environment: MYSQL_ROOT_PASSWORD: password tomcat01: depends_on: - db image: docker.io/tomcat:latest volumes: - /tomcat01/webapps:/usr/local/tomcat/webapps links: - db:db ports: - "8081:8080" restart: always tomcat02: depends_on: - db image: docker.io/tomcat:latest volumes: - /tomcat02/webapps:/usr/local/tomcat/webapps links: - db:db - tomcat01:tomcat01 ports: - "8082:8080" restart: always
FROM tomcat:latest MAINTAINER "hanqunfeng <[email protected]>" ADD web.war /usr/local/tomcat/webapps/
tomcat01: depends_on: - db build: /dockerfile links: - db:db ports: - "8081:8080" restart: always