The installation of docker can go to my other blog docker blog link
install mysql
Determine the version to pull the mirror
docker pull mysql:5.7.36
start mysql service
Start the mysql service, run it in the background, specify the root user password, and specify the container name
docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 -d -p 3306:3306 mysql:5.7.36
- --name container name
- -e MYSQL_ROOT_PASSWORD=xxx Specify a password for the root user
- -d run in the background
- -p host port: container port
The above run command does not use the data volume and persists the data to the host system
Start mysql + data volume persistence
Start the mysql service, run it in the background, specify the root user password, specify the container name, and use the data volume to persist the data to the host system
Note: According to the dockerhub description, it is known that the mysql storage file directory is placed in the container in this directory /var/lib/mysql
docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 -d -p 3306:3306 -v mysqldata:/var/lib/mysql mysql:5.7.36
Modify mysql configuration
If you want to modify the mysql configuration file according to your own needs, you can also mount the corresponding directory together
docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 -d -p 3306:3306 -v mysqldata:/var/lib/mysql -v mysqlconfig:/etc/mysql/conf.d -v mysqllog:/var/log/mysql mysql:5.7.36
docker exec -it 容器id bash
mysql -u root -p123456
SHOW VARIABLES LIKE 'character%';
If the character set is incorrectly inserted into Chinese, there will be problems
Modify database configuration through data volumes
cd /var/lib/docker/volumes/mysqlconfig/_data
vim my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
Be sure to restart the container
install tomcat
pull image
docker pull tomcat:9.0-jdk8-corretto
Start a basic tomcat service
docker run -d -p 8080:8080 --name tomcat tomcat:9.0-jdk8-corretto
- --name container name
- -d run in the background
- -p host port: container port
Access discovery by ip address
It is found that the webapps directory is empty.
After the modification, you can visit the tomcat page again,
or you can directly pull the image of the boss.
pull image
docker pull tomcat:8.0.52-jre8
run
docker run -d -p 8080:8080 --name tomcat tomcat:8.0.52-jre8
Automount via data volume
Note that the directory where the web application is deployed in the container is /usr/local/tomcat/webapps and the configuration file is /usr/local/tomcat/conf
docker run -d -p 8080:8080 --name tomcat -v apps:/usr/local/tomcat/webapps tomcat:8.0.52-jre8
Create a folder in the directory corresponding to the data volume, write index.html, and access ip::8080/emp/index.html
Mount configuration file directory
docker run -d -p 8080:8080 --name tomcat -v apps:/usr/local/tomcat/webapps -v confs:/usr/local/tomcat/conf tomcat:8.0.52-jre8
If the configuration information does not take effect immediately (such as port), it may be necessary to create a new container with the data volume to take effect.
Manually mount tomcat9 and run
# -v表示挂载,前面的目录为宿主机目录结构,后面的目录为容器中的目录结构
docker run --name tomcat -p 8080:8080
-v /usr/local/tomcat/webapps:/usr/local/tomcat/webapps
-v /usr/local/tomcat/conf:/usr/local/tomcat/conf -d tomcat:9.0-jdk8-corretto
Here we start another tomcat container, and then copy a server.xml file from the container into the mount conf folder
docker run --name tomcat1 -p 8080:8080 -d tomcat:9.0-jdk8-corretto
docker exec -it ad37af bash
copy command
docker cp tomcat1:/usr/local/tomcat/conf/ /usr/local/tomcat/
restart tomcat
docker start tomcat
Because the 9 version of tomcat webapps is empty, you need to copy webapps.dist to access
cd webapps.dist/
cp -r ./* ../webapps
access to success
install redis
pull image
docker pull redis:6.2.5
Automatically mount and run containers
docker run -p 6379:6379 --name redis --privileged=true -v redisconfig:/etc/redis -v redisdata:/data -d redis:6.2.5 redis-server /etc/redis/redis.conf
Copy the configuration file
cp ./redis.conf /var/lib/docker/volumes/redisconfig/_data
Remember:
do not configure daemonize yes, otherwise the container cannot be started: stop immediately after starting
Manual mount installation steps
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
Create a new file redis.conf in the newly created redis/conf with the following contents:
#bind 127.0.0.1 //允许远程连接
protected-mode no
appendonly yes //持久化
requirepass 123456 //密码
start up
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf