Docker application deployment
1. Deploy MySQL
- Search mysql mirror
docker search mysql
- Pull mysql image
docker pull mysql:5.6
- Create a container, 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 port 3306 of the container to port 3307 of the host.
- -v $PWD/conf:/etc/mysql/conf.d : Mount conf/my.cnf in the host's current directory to /etc/mysql/my.cnf in 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 root user's password.
- Enter the container and operate mysql
docker exec –it c_mysql /bin/bash
- Use an external machine to connect to mysql in the container
2. Deploy Tomcat
- Search tomcat mirror
docker search tomcat
- Pull the tomcat image
docker pull tomcat
- Create a container, 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 port 8080 of the container to port 8080 of the host
**-v $PWD:/usr/local/tomcat/webapps: **Mount the current directory in the host to the webapps of the container
-
- Use an external machine to access tomcat
3. Deploy Nginx
- Search nginx mirror
docker search nginx
- Pull the nginx mirror
docker pull nginx
- Create a container, 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.
- -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf : Mount /conf/nginx.conf in the current directory of the host to: /etc/nginx/nginx.conf in the container. 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
- Access nginx from an external machine
4. Deploy Redis
- Search redis mirror
docker search redis
- Pull the 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
- Connect to redis using an external machine
./redis-cli.exe -h 192.168.149.135 -p 6379
redis
2. 拉取redis镜像
```shell
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
- Connect to redis using an external machine
./redis-cli.exe -h 192.168.149.135 -p 6379