Mysql Redis Nginx Redis for Docker series 4 application deployment

1. MySQL deployment

Specific steps

1. Search for the mysql image
2. Pull the mysql image
3. Create the container
4. Operate the mysql in the container

1. Search mysql mirror

2. Pull the mysql mirror

3. Create a container

4. Operate mysql in the container

2.Tomcat deployment

Specific steps

1. Search for tomcat image
2. Pull tomcat image
3. Create container
4. Use external machine to access tomcat

1. Search for tomcat mirror

docker search tomcat

2. Pull the tomcat image

docker pull tomcat

3. Create a container

# 在/root目录下创建tomcat目录用于存储tomcat数据信息
mkdir ~/tomcat
cd ~/tomcat
docker run -id --name=c_tomcat \
-p 8080:8080 \
-v $PWD:/usr/local/tomcat/webapps \
tomcat 

He will automatically start tomcat for you
Insert picture description here

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

4. Use an external machine to access tomcat

Create a test folder in the tomcat directory and add the index.html page to the folder
Insert picture description here

Insert picture description here

Insert picture description here

note

This access path is relative to the root path of the tomcat we created. In the future, we need to deploy the project to tomcat. Just place the created project in the tomcat directory.

3.Nginx deployment

Specific steps

1. Search for Nginx image
2. Pull Nginx image
3. Create container, set port mapping, directory mapping
4. Use external machine to access nginx

1. Search for Nginx mirror

docker search nginx

2. Pull the Nginx image

docker pull nginx

3. Create a container, set up 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;
}

This sentence is executed in the nginx directory
**

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

Insert picture description here

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 the container: /etc/nginx/nginx.conf. Configuration directory

  • -v $PWD/logs:/var/log/nginx : Mount the logs directory in the current directory of the host to the container's /var/log/nginx. Log directory

4. Use an external machine to access nginx

Insert picture description here

Precautions

1. The network service in the container and the external machine cannot communicate directly

2. The external machine and the host can communicate directly

3. The host and the container can communicate directly

4. When the network service in the container needs to be accessed by an external machine, the port of the service provided in the container can be mapped to the port of the host machine. The external machine accesses the port of the host machine, thereby indirectly accessing the service of the container.

5. This operation is called: port mapping

Insert picture description here

1. Search mysql mirror

docker search mysql

2. Pull the mysql mirror

docker pull mysql

3. Create a container

# 在/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

Insert picture description here
Insert picture description here

Enter the container to log in to mysql
Insert picture description here

Use the database connector to connect to mysql
**
Note that the connection port here is the port connected to the server, not the container. We map the server port 3307 to the container's 3306 port
Insert picture description here

Parameter Description

  • -p 3307:3306 : Map the 3306 port of the container to the 3307 port of the host.

  • -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 in the current directory of the host to the container's /logs. Log directory

  • -v $PWD/data:/var/lib/mysql : Mount the data directory in the current directory of the host to the container's /var/lib/mysql. Data directory

  • **-e MYSQL_ROOT_PASSWORD=123456: ** Initialize the password of the root user.

4. Operate mysql in the container

4. Redis deployment

Specific steps

1. Search for redis mirror
2. Pull redisl mirror
3. Create container, set port mapping
4. Use external machine to connect to redis

1. Search for redis mirror

docker search redis

2. Pull the redisl mirror

docker pull redis:5.0

3. Create a container and set up port mapping

docker run -id --name=c_redis -p 6379:6379 redis:5.0

Insert picture description here

4. Use an external machine to connect to redis

Insert picture description here

Guess you like

Origin blog.csdn.net/pjh88/article/details/114731927
Recommended