Make a note, in case something goes wrong there’s a how-to guide, if you have any questions

All kinds of installation

Note that there are two ways to create containers:

  1. Each is added with a bunch of arguments via the Docker run directive
  2. Docker-compose is recommended for convenience

Docker

To install the Docker

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
systemctl daemon-reload && systemctl start docker
# test
docker run hello-world
Copy the code

Configuration mirror accelerator, I use ali cloud cr.console.aliyun.com/cn-hangzhou…

sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": } EOF sudo systemctl daemon-reload sudo systemctl restart dockerCopy the code

Enabling Remote Access

Vi/lib/systemd/system/docker. Service # modified ExecStart at the beginning of a line of ExecStart = / usr/bin/dockerd -h TCP: / / 0.0.0.0:2375 - H unix://var/run/docker.sock systemctl daemon-reload service docker restartCopy the code

Add a security group on the ECS and release port 2375

MySQL

docker pull mysql
Run the container
docker run -itd --name mysql -p 3306: 3306 -e MYSQL_ROOT_PASSWORD=123456 mysql 
Mysql is the name of the container because docker does not have vim
docker cp mysql:/etc/mysql/my.cnf /root/my.cnf
vim /root/my.cnf
The memory usage is too high
table_open_cache=512
table_definition_cache=400
docker cp /root/my.cnf mysql:/etc/mysql/my.cnf
# Enter container
docker exec -it mysql bash 
# in mysql
mysql -u root -p 

Copy the code

Redis

docker pull redis
Create a folder to store configuration files and persistent data
mkdir /root/docker/redis
mkdir /root/docker/redis/data
cd /root/docker/redis
Download the configuration file and modify it
wget https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf -O redis.conf
#------ Modified content ------
bind 127.0. 01. # comment out this section because redis is restricted to local access only
protected-mode no # Default yes, enable protected mode, restrict local access
daemonize no If you change the default no to yes, you can start redis in daemon mode. You can run it in background mode unless you kill the process
dir  . / Enter the local redis database folder (optional)
appendonly yes # Redis persistence (optional)
requirepass  password Configure redis access password
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# run with --privileged=true will fail startup
docker run -d --name redis -p 6379: 6379 -v /root/docker/redis/redis.conf:/etc/redis/redis.conf -v /root/docker/redis/data:/data redis redis-server /etc/redis/redis.conf 
# enter
docker exec -it redis redis-cli
auth password
Copy the code

Nginx

The main job is to mount the configuration file into docker’s nginx

If you need to configure the reverse proxy, ensure that the format is correct

# the first
location /proxy/ {
proxy_pass http://127.0.0.1/;
}
# agent to URL: http://127.0.0.1/test.html

# second type (relative to the first type, the last one less /)
location /proxy/ {
proxy_pass http://127.0.0.1;
}
# agent to URL: http://127.0.0.1/proxy/test.html

# 3:
location /proxy/ {
proxy_pass http://127.0.0.1/aaa/;
}
The agent to the URL: http://127.0.0.1/aaa/test.html

# 4 type (relative to type 3, last one less /)
location /proxy/ {
proxy_pass http://127.0.0.1/aaa;
}
# agent to URL: http://127.0.0.1/aaatest.html
Copy the code

steps

docker pull nginx
mkdir nginx
cd nginx
Create directory for plugins
mkdir html logs conf conf.d
Create a container to copy the configuration file and delete it
#ID is the container ID
docker run -itd nginx nginx
docker cp ID:/etc/nginx/nginx.conf conf/nginx.conf
docker cp ID:/etc/nginx/conf.d/default.conf conf.d/default.conf

# Basic configuration
vim conf/nginx.conf
# Open gzip
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- #
gzip  on;
gzip_comp_level 6;
gzip_types application/javascript text/css text/xml;
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- #
# configure proxy
vim nginx/conf.d/default.conf
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- #
server {
    listen       80;
    server_name  ip;

    #charset koi8-r;
    #access_log /var/log/nginx/host.access.log main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
}
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- #

# run
docker run -d --name nginx -p 80: 80 --net host \
-v /root/nginx/html:/usr/share/nginx/html \
-v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /root/nginx/logs:/var/log/nginx \
-v /root/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
nginx

Copy the code

RabbitMQ

# It comes with a console
docker pull rabbitmq:management
Copy the code

Docker-compose

Test found that the time of container and the host machine in, using volumes: – “/ etc/localtime: / etc/localtime: ro” solution

docker-compose -f docker-compose-server.yml up -d
Copy the code
version: '3'
services:
  nginx:
    image: nginx
    ports:
      - "80:80"
    container_name: "nginx"
    volumes:
      - "/root/nginx/html:/usr/share/nginx/html"
      - "/root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf"
      - "/root/nginx/logs:/var/log/nginx"
      - "/root/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf"
      - "/etc/localtime:/etc/localtime:ro"
  mysql:
    image: mysql
    ports:
      - "3306:3306"
    container_name: "mysql"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      MYSQL_ROOT_PASSWORD: 123456
  redis:
    image: redis
    ports:
      - "6379:6379"
    container_name: "redis"
    volumes:
      - "/root/docker/redis/redis.conf:/etc/redis/redis.conf"
      - "/root/docker/redis/data:/data"
      - "/etc/localtime:/etc/localtime:ro"
    command: redis-server /etc/redis/redis.conf
  rabbitmq:
    image: rabbitmq:management
    ports:
      - "5672:5672"
      - "15672:15672"
    container_name: "rabbitmq"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
Copy the code

Adding virtual Memory

Since the server has only 2G memory, it takes about 300M to run a Java container. If there are too many containers, other containers will be stopped due to insufficient memory. The mysql database was jammed in the beginning, and the problem was not found after searching for a long time. Finally, it was found to be due to insufficient memory. Therefore, virtual memory is set to expand capacity

Blog.csdn.net/herobacking…

1Open the terminal, switch to the root user, and enter: free -m Displays the memory status
[maker@LLM ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:            992         189          79          13         722         614
Swap:             0           0           0
Swap is zero virtual memory
 
2. Select a larger partition and create a partition file
[root@LLM ~]# dd if=/dev/zero of=/opt/swap bs=1024 count=1024000
1024000+ 0 records in
1024000+ 0 records out
1048576000 bytes (1.0 GB) copied, 16.6877 s, 62.8 MB/s
[root@LLM ~]#
This command creates a 1 GB virtual memory file named swap in the opt partition
 
3. Set the swap file to the swap partition file
chmod 600 /opt/swap    // Change the swap file permissions
[root@LLM ~]# mkswap /opt/swap
Setting up swapspace version 1. size = 1023996 KiB
no label, UUID=fc47f29e-31af-401e-856d-0fec5262179e
 
4. Activate swap to enable partition file swap
swapon /opt/swap
5.Now look at the result
[root@LLM ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            992         191          63          13         737         625
Swap:           999           0         999    
Copy the code

Vue packaging

# change the vue. Config. Js
publicPath: '/'
# run
npm run build:prod
# If not successful, see if the build of scripts in package.json has parameters
Copy the code

Add a DIS folder after success

Copy all the files in the dist path into the HTML you just created

The address page is displayed as follows

The background of packaging

The default docker environment is IP :2375, so you need to add DOCKER_HOST= TCP :// IP :2375 to the environment variable, and then restart

Dockerfile

For example, create a Dockerfile file in the root path of the eureka-server-single module

The following

FROM java:8
VOLUME /tmp
ADDThe target/eureka - server - single - 0.0.1 - the SNAPSHOT. Jar app. The jar
RUN bash -c 'touch /app.jar'
EXPOSE 8761
ENTRYPOINT ["java"."-jar"."/app.jar"]
Copy the code

Configuration is found on the Internet, roughly explain the meaning:

FROM is the base image

The first half of ADD is the path to the project after it has been jar packed

RUN is the command to execute

EXPOSE is the port to EXPOSE

pom.xml

The package uses the Dockerfile-maven-plugin and is therefore configured under Build

			<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.13</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <! -- Mirror name -->
                    <repository>${project.artifactId}</repository>
				   <! The default tag for a mirror is latest-->
                    <tag>latest</tag>
                    <dockerfile>Dockerfile</dockerfile>
                    <! -- Dockerfile path -->
                    <contextDirectory>${project.basedir}</contextDirectory>
                    <buildArgs>
                        <! -- Project jar package path -->
                        <! -- finalName = artifactId + version-->
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>
Copy the code

packaging

Once configured, Lifecycle can be packaged directly with Maven

Multi-module packaging see blog.csdn.net/qq_30299977…

docker-compose

pit

1. Packaging failure

Be aware that the packaged project does not depend on other packages. For example, this project needs oAUTH2 module to start first

Continue to update if there are problems

Welcome to pay attention to the public account