当前位置: 首页 > 工具软件 > mix_docker > 使用案例 >

docker部署常用软件

马煌
2023-12-01

docker安装

安装

卸载docker

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
=
 sudo yum remove docker-ce docker-ce-cli containerd.io
 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

yum 安装

#1. 需要的安装包
sudo yum install -y yum-utils

#2. 设置镜像的仓库
 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#3.更新yum软件包索引
yum makecache fast
#4. 安装docker
sudo yum install docker-ce docker-ce-cli containerd.io

#5 启动docker
sudo systemctl start docker

#6.测试
sudo docker run hello-world

#7.查看docker版本
docker version


 
#9.加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://cmab5ofv.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

部署Springboot

DockerFile

FROM java:8

COPY *.jar /app.jar

EXPOSE 8888

ENTRYPOINT ["java","-jar","/app.jar","--spring.profiles.active=prod"]

构建镜像

docker build -t demo .

运行

docker run -d -p 8888:8888 --name demoproject demo

tips

1.docker出现Error response from daemon: driver failed programming external connectivity on endpoint解决方法
重启docker:systemctl restart docker

部署portainer

docker run -d -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

部署MySQL

安装

mkdir -p /my/mysql/conf #挂载配置文件
mkdir -p /my/mysql/data #挂载数据文件
mkdir -p /my/mysql/logs #挂载日志文件
vi  /my/mysql/conf/my.cnf

[client]
default-character-set = utf8mb4  # 客户端数据默认字符集
 
[mysql]
default-character-set = utf8mb4 # 数据库默认字符集
 
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
wait_timeout=1200
interactive_timeout=1200
 
character-set-client-handshake = FALSE
character-set-server = utf8mb4         # 服务端默认字符集
collation-server = utf8mb4_unicode_ci  # 连接层默认字符集
init_connect = 'SET NAMES utf8mb4'     # 指定每次连接的字符集utf8mb4
 group_concat_max_len = 102400  #字符串拼接最大字符数
max_connections        = 2000  # 最大连接数

#1. 拉去镜像
docker pull mysql:5.7 
#2. 运行

docker run \
--name mysql \
-p 3306:3306 \
--restart=always \
 -e TZ="Asia/Shanghai"  \
 -v /my/mysql/conf:/etc/mysql/ \
 -v /my/mysql/data:/var/lib/mysql  \
 -v /my/mysql/logs:/var/log/mysql  \
 -e MYSQL_ROOT_PASSWORD=Panchengkao1  \
 -d mysql:5.7



#3.允许远程访问
grant all privileges on *.* to root@'%' identified by "Panchengkao1";
#4. 刷新
flush privileges;

create database test;
show create database test;

部署Redis

安装

#1.创建文件夹
mkdir -p /my/redis/data
mkdir -p /my/redis/conf

#2.在conf目录下创建redis.conf 将以下输入
#bind 127.0.0.1 //允许远程连接
protected-mode no 
appendonly yes //持久化
requirepass Panchengkao1 //密码 

#3.运行

docker run --name my_redis -p 6379:6379 --restart=always  -v /my/redis/data:/data -v /my/redis/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf 

#4.进入redis
docker exec -it my_redis redis-cli

在conf中添加

#bind 127.0.0.1 //允许远程连接
protected-mode no
appendonly yes //持久化
requirepass 123456 //密码 

部署Nginx

#1.进入到安装包
cd /usr/local/nginx-1.15.0/
#2.configure
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#3.编译
make make install
#4.配置nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen    443 ssl;
        server_name  superqp.top;
	ssl_certificate superqp.top_bundle.crt; 
        #私钥文件名称
        ssl_certificate_key superqp.top.key; 
        ssl_session_timeout 5m;
         #请按照以下协议配置
        ssl_protocols TLSv1.2 TLSv1.3; 
        #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
        ssl_prefer_server_ciphers on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   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   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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}



bug

docker run --security-opt seccomp=unconfined  开启调试权限
 类似资料: