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
相關文章
相關標籤/搜索