Docker容器配置

docker run --name study -v /Users/ackerman/Projects/study:/var/www/study -p 80:80 -p 3306:3306 -p 2222:22 -d ubuntu-lnmp:18.04php

 

· --name study 是建立一个名字为 study 的容器mysql

· -v /Users/ackerman/Projects/study:/var/www/study 是将本地的 /Users/ackerman/Projects/study 和 容器中的 /var/www/study 进行映射nginx

· -p 是对端口进行映射 ,分别是 http,MySQL,SSHsql

· -d 容器后台运行docker

· ubuntu-lnmp:18.04 就是选择的环境数据库

 

docker ps  查看目前正在运行的容器ubuntu

docker ps -a 查看本机中全部的容器 (包括没有运行的)vim

 

docker rm study  删除名字为 study 的容器bash

 

dokcer exec -it study bash  进入容器内部进行操做,study 是容器名字php7

 

cd /etc/nginx/sites-available

 

vim study  对文件进行修改

 

Nginx 配置以下

server {
     listen 80;
     root /var/www/blog/public;
     index index.php;
     server_name blog.local;

     location / {
         try_files $uri $uri/ /index.php?$query_string;
     }
     location ~\.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
     }

     location ~/\.ht {
         deny all;
     }
 }

 

cd /etc/nginx/sites-enabled 

 

ln -s /etc/nginx/sites-available/study study 创建一个软链接到当前到 enabled 目录中

 

nginx -s reload 重载

 

 

 

与 MySQL 数据库创建链接

首先须要先创建一个 mysql 的容器

create database ackerman default character set utf8mb4 collate utf8mb4_unicode_ci;
CREATE USER 'ackerman'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
grant all privileges on ackerman.* to 'ackerman'@'%';
flush privileges;

这样配置以后咱们就能够利用 ackerman 这个用户名去访问数据库了

mysql -uackerman -p123456

 

而后咱们再须要建立一个容器去链接咱们以前建立的 mysql001 容器

docker run --name study -v /Users/ackerman/Projects/study:/var/www/study -p 80:80 -p 3306:3306 -p 2222:22 --link mysql001 -d ubuntu-lnmp:18.04

采用下面的方法便可以访问数据库

mysql -hmysql001 -uackerman -p123456
相关文章
相关标签/搜索