table of Contents
Docker application deployment
First, deploy MySQL
- Search mysql mirror
docker search mysql
- Pull mysql image
docker pull mysql:5.6
- Create containers, set port mapping, directory mapping
# 在/root目录下创建mysql目录用于存储mysql数据信息
mkdir ~/mysql
cd ~/mysql
docker run -id \
-p 3307:3306 \
--name=c_mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.6
- Parameter Description:
- -p 3307: 3306 : Map the 3306 port of the container to the 3307 port of the host machine.
- -v $ PWD / conf: /etc/mysql/conf.d : Mount conf / my.cnf in the current directory of the host to /etc/mysql/my.cnf of the container. Configuration directory
- -v $ PWD / logs: / logs : Mount the logs directory under the current directory of the host to / logs of the container. Log directory
- -v $ PWD / data: / var / lib / mysql : Mount the data directory under the current directory of the host to / var / lib / mysql of the container. Data directory
- **-e MYSQL_ROOT_PASSWORD = 123456: ** Initialize the password of the root user.
- Enter the container and operate mysql
docker exec –it c_mysql /bin/bash
- Use external machine to connect mysql in the container
Second, deploy Tomcat
- Search tomcat image
docker search tomcat
- Pull tomcat image
docker pull tomcat
- Create containers, set port mapping, directory mapping
# 在/root目录下创建tomcat目录用于存储tomcat数据信息
mkdir ~/tomcat
cd ~/tomcat
docker run -id --name=c_tomcat \
-p 8080:8080 \
-v $PWD:/usr/local/tomcat/webapps \
tomcat
-
Parameter Description:
-
**-p 8080: 8080: ** Map the 8080 port of the container to the 8080 port of the host
**-v $ PWD: / usr / local / tomcat / webapps: ** Mount the current directory in the host to the webapps of the container
-
- Use external machine to access tomcat
3. Deploy Nginx
- Search nginx mirror
docker search nginx
- Pull nginx image
docker pull nginx
- Create containers, set port mapping, directory mapping
# 在/root目录下创建nginx目录用于存储nginx数据信息
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
# 在~/nginx/conf/下创建nginx.conf文件,粘贴下面内容
vim nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
docker run -id --name=c_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx
- Parameter Description:
- -p 80:80 : Map port 80 of the container to port 80 of the host machine.
- -v $ PWD / conf / nginx.conf: /etc/nginx/nginx.conf : Mount /conf/nginx.conf in the current directory of the host to the container: /etc/nginx/nginx.conf. Configuration directory
- -v $ PWD / logs: / var / log / nginx : Mount the logs directory under the current directory of the host to / var / log / nginx of the container. Log directory
- Use external machine to access nginx
Fourth, deploy Redis
- Search redis mirror
docker search redis
- Pull redis image
docker pull redis:5.0
- Create a container and set up port mapping
docker run -id --name=c_redis -p 6379:6379 redis:5.0
- Use an external machine to connect to redis
./redis-cli.exe -h 192.168.149.135 -p 6379