打折购物就上打折屋,打折屋Dazhewu.com带你来嗨,领券再买,更省钱,半价抢先购!

docker搭建MySQL、Nginx服务

公告 扩产网 100℃ 0评论

1、docker搭建MySQL,很简单,拉镜像,执行命令


1、docker pull mysql:5.7.33

2、docker run -p 3307:3306 --name mysql-5.7.33 \
-v /Users/kuochan.com/data/program/docker/mysql-5.7.33/conf:/etc/mysql \
-v /Users/kuochan.com/data/program/docker/mysql-5.7.33/logs:/var/log/mysql \
-v /Users/kuochan.com/data/program/docker/mysql-5.7.33/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123321 \
-d mysql:5.7.33

2、docker搭建Nginx挂载目录稍微复杂一点,因为网上说docker只能挂在目录,不能挂在文件,所以挂在目录前要先把配置文件创建好,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;
}

要在挂载目录:/Users/kuochan.com/data/program/docker/nginx-1.7.5/conf/,把nginx.conf创建好,不然会报错:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:59: mounting “/Users/beike/data/program/docker/nginx-test-1.7.5/conf/nginx.conf” to rootfs at “/var/lib/docker/overlay2/b6a74b4a1983d2907085a3d9f28d49a72aac6c58c8be59f7a9ccfce9e5496a6c/merged/etc/nginx/nginx.conf” caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

执行下面命令就可以了


1、docker pull nginx:1.7.5

2、docker run -d -p 8089:80 --name nginx-1.7.5 -v /Users/kuochan.com/data/program/docker/nginx-1.7.5/www:/usr/share/nginx/html -v /Users/kuochan.com/data/program/docker/nginx-1.7.5/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/kuochan.com/data/program/docker/nginx-1.7.5/logs:/var/log/nginx nginx:1.7.5

转载请注明:扩产网 » docker搭建MySQL、Nginx服务

喜欢 (2)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址