Docker搭建开发环境: Nginx和Mysql

Docker搭建开发环境: Nginx和Mysql

1.拉取Nginx和Mysql image

docker pull nignx

docker pull mysql:5.7.22

2.启动Nginx

docker run -d --name mynginx  -p 80:80 -v /opt/local/nginx/logs:/var/log/nginx -v /opt/local/nginx:/etc/nginx nginx

docker run -d --name nginx  -p 82:80 -v /opt/local/nginx/:/etc/nginx nginx

docker run --detach \
--name xjj_nginx -p 80:80 -p 443:443 \
-v /root/cloud/nginx/html/:/usr/share/nginx/html:rw \
-v /root/cloud/nginx/config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:rw \
-v /root/cloud/nginx/logs/:/var/log/nginx/:rw \
-v /root/cloud/nginx/ssl/:/ssl -d nginx

-p 80:80 是将容器内80端口映射服务器80端口

–name 给容器起个名字

-d 是作为守护进程启动

-v 配置挂载路径 宿主机路径:容器内的路径

在这里挂载了两个 目录到 宿主机,一个是配置文件(etc/nginx),;另一个是日志文件(/var/log/nginx);

当然你要确保在宿主机有你指定的目录,并且有对应的配置文件才能启动

2.1 default.conf

server {
    listen       443;
    server_name  www.xinjiujiu.top;

    ssl on; #如果强制使用https,则要打开
    ssl_certificate   /ssl/1536775258034.pem;
    ssl_certificate_key  /ssl/1536775258034.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

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

    location / {
       # root   /usr/share/nginx/html;
        #index  index.html index.htm;
	proxy_pass https://localhost:8088/user/home
    }

    #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;
    }

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

server {
	listen		80;
	server_name 	www.xinjiujiu.top;
	rewrite ^(.*) https://$server_name$1 permanent;

}

3.启动mysql

docker run --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.22

本地端口3306,密码123456

MYSQL_ROOT_PASSWORD=123456 启动时设置是多少就是多少

docker ps //查看启动的容器

这里写图片描述

3.1 mysql启动后,远程无法访问的问题

因为mysql启动后 123456是原始密码无法提供远程的访问,所以只能修改原是配置,需要进入到容器内部,

3.1.1进入镜像中的mysql(ti 后面的字符串是mysql镜像ID)
docker exec -ti  063154b87901 /bin/bash
3.1.2 登录mysq
mysql -u root -p
3.1.3修改root配置
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

你可能感兴趣的:(技术杂谈)