美文网首页
Docker 启动数据库和nginx

Docker 启动数据库和nginx

作者: Rinaloving | 来源:发表于2022-03-29 23:27 被阅读0次

    我把数据库,项目后台(.net core ) , 项目前端(vue) 都打包安装在docker 基础镜像centos当中,如何启动呢。

    以启动mysql 数据库为例

    [root@localhost ~]# docker run -itd --name=t4 --privileged=true -p 3306:3306 mynjdk2 /usr/sbin/init
    019a32d3323ef4cfa22d8a55d771d0c9db2541d01ffcbf35cedd2bee00c95d42
    [root@localhost ~]# docker ps -a
    CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
    019a32d3323e   mynjdk2             "/usr/sbin/init"         32 seconds ago   Up 27 seconds             0.0.0.0:3306->3306/tcp, :::3306->3306/tcp   t4
    f97ce19502a7   mynjdk2             "/usr/sbin/init"         10 minutes ago   Up 6 minutes              0.0.0.0:8888->5003/tcp, :::8888->5003/tcp   t3
    332a55111b56   mynjdk2             "/usr/sbin/init"         24 minutes ago   Up 3 minutes              0.0.0.0:82->80/tcp, :::82->80/tcp           t2
    b04263a3ee14   mynjdk              "/usr/sbin/init"         4 days ago       Exited (137) 4 days ago                                               t1
    f325c82add38   centos:7            "/usr/sbin/init"         4 days ago       Up 58 minutes                                                         mycentos7
    26a7ed9e7aa7   centos:7            "/bin/bash"              4 days ago       Exited (1) 4 days ago                                                 mycentos
    4194e389a5e1   nginx:latest        "/docker-entrypoint.…"   6 days ago       Up About an hour          0.0.0.0:81->80/tcp, :::81->80/tcp           my_nginx_2022d5cef486db6c   dockernjdk:latest   "dotnet WebApi.dll"      7 days ago       Exited (0) 7 days ago                                                 dockernjdk
    e91d88e285c7   dockerdemo:latest   "dotnet DockerDemo.d…"   8 days ago       Exited (0) 7 days ago                                                 dockerdemo
    [root@localhost ~]# docke ps
    -bash: docke: command not found
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS             PORTS                                       NAMES
    019a32d3323e   mynjdk2        "/usr/sbin/init"         39 seconds ago   Up 34 seconds      0.0.0.0:3306->3306/tcp, :::3306->3306/tcp   t4
    f97ce19502a7   mynjdk2        "/usr/sbin/init"         10 minutes ago   Up 6 minutes       0.0.0.0:8888->5003/tcp, :::8888->5003/tcp   t3
    332a55111b56   mynjdk2        "/usr/sbin/init"         24 minutes ago   Up 3 minutes       0.0.0.0:82->80/tcp, :::82->80/tcp           t2
    f325c82add38   centos:7       "/usr/sbin/init"         4 days ago       Up 58 minutes                                                  mycentos7
    4194e389a5e1   nginx:latest   "/docker-entrypoint.…"   6 days ago       Up About an hour   0.0.0.0:81->80/tcp, :::81->80/tcp           my_nginx_2022
    [root@localhost ~]# docker exec -it t4 /bin/bash
    [root@019a32d3323e /]# 
    
    

    安装如下设置,解决远程无法连接问题

    mysql> select 'host' from user where user ='root';
    +------+
    | host |
    +------+
    | host |
    | host |
    | host |
    | host |
    | host |
    | host |
    +------+
    6 rows in set (0.06 sec)
    
    mysql> update user set host ='%' where user='root';
    ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
    mysql> select host from user where user ='root';
    +----------------+
    | host           |
    +----------------+
    | %              |
    | 127.0.0.1      |
    | 172.17.0.6     |
    | 192.168.70.131 |
    | ::1            |
    | f325c82add38   |
    +----------------+
    6 rows in set (0.14 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.17 sec)
    
    mysql> exit;
    Bye
    [root@e61f3ef965f4 /]# 
    

    相关文章

      网友评论

          本文标题:Docker 启动数据库和nginx

          本文链接:https://www.haomeiwen.com/subject/jkxijrtx.html