#啓動docker服務
service docker start
#搜索可用docker鏡像
#https://docs.docker.com/engine/reference/commandline/search/
docker search --filter "stars=3" --filter "is-official=true" mysql
#搜索並指定版本的鏡像(搜索並查看鏡像版本號)
docker search mysql:5.7
#查看本地鏡像或容器的版本信息
docker inspect --format "{{.Config.Env}}" mysql:5.6
#查看本地容器的ip地址
docker inspect --format='{{.NetworkSettings.IPAddress}}' test_phpfpm
#在Docker裏面安裝vim編輯器
apt-get update
apt-get install vim
#docker容器操做
docker stop test_nginx
docker start test_nginx
docker restart test_nginx
docker rm test_nginx
docker rename test_nginx test_nginx2php
#從倉庫拉取一個MySql的鏡像
docker pull mysql:5.6
#查看咱們剛剛拉下來的mysql的鏡像
docker images
#運行並啓動一個容器
mkdir -p /docker/mysql/data /docker/log/mysql
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=dbPwd000 -v /docker/mysql/data:/var/lib/mysql -v /docker/log/mysql:/var/log/mysql --name test_mysql mysql:5.6
#查看咱們剛剛建立的容器
docker ps -a
#進入到咱們剛剛建立的容器中,輸入命令
docker exec -ti test_mysql /bin/bash
#登陸MySQL
mysql -uroot -p dbPwd000
#建立一個應用用戶
GRANT ALL PRIVILEGES ON *.* TO 'fhzbuser'@'%' IDENTIFIED BY 'fhzbPwd!23_';
FLUSH PRIVILEGES;
#建立一個數據庫
CREATE DATABASE IF NOT EXISTS db_test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
#建立一個數據表
create table if not exists db_test.t_test (id int auto_increment primary key,title varchar(32) not null default '',createdTime timestamp not null default CURRENT_TIMESTAMP) ENGINE=InnoDB default CHARSET=utf8;
insert into db_test.t_test (title) values ('title 1'),('title 2'),('title 3'),('title 4'),('title 5');css
#拉取php-fpm的鏡像
docker pull php:5.6-fpm
#在本地建立默認配置文件
mkdir -p /docker/conf/php/
echo -e "data.timezone = PRC\nmemory_limit = 128m\nupload_max_filesize = 16m\npost_max_size = 32m\nmax_execution_time = 600\nmax_input_time = 600\n" > /docker/conf/php/test_phpfpm.ini
#建立一個phpfpm容器(php.int配置文件默認不存在,需手動建立)
docker run -d -p 9000:9000 --link test_mysql:mysql -v /docker/www/html/test_html:/var/www/html -v /docker/conf/php/test_phpfpm.ini:/usr/local/etc/php/conf.d/php.ini --name test_phpfpm php:5.6-fpm
#進入到咱們剛剛建立的容器中,輸入命令
docker exec -ti test_phpfpm /bin/bash
#在/var/www/html目錄下新建一個index.php文件
touch /var/www/html/index.php
#在容器中安裝pdo擴展
docker-php-ext-install pdo_mysql
#在容器中安裝非php官方擴展(redis擴展)
# 參考文章:https://stackoverflow.com/questions/31369867/how-to-install-php-redis-extension-using-the-official-php-docker-image-approach
mkdir -p /usr/src/php/ext/
curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/2.2.8.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-2.2.8 /usr/src/php/ext/redis \
&& docker-php-ext-install redis
#執行php -m查看已安裝的擴展模塊
php -m
#重啓容器,使配置生效
docker restart test_phpfpmhtml
#拉取一個nginx鏡像
docker pull ngixn
#運行nginx容器
docker run -d -p 80:80 --privileged=true --link test_phpfpm -v /docker/www/html/test_html:/var/www/html --name test_nginx nginx
#進入nginx容器
docker exec -ti test_nginx /bin/bash
#修改默認站點配置文件以支持php腳本(注意php節點的root設置,不少時候提示php文件未找到都是由於這裏設置錯了)mysql
vi /etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; root /var/www/html; index index.html index.htm index.php; access_log /var/www/wwwlogs/test_nginx_access.log; #error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #include enable-php.conf; location ~ \.php$ { # important, php file not found is because root setting wrong. root /var/www/html; fastcgi_index index.php; fastcgi_pass 172.17.0.3:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } }
#在容器裏面重啓nginxnginx
service nginx reload
#編輯index.phpgit
vi /var/www/html/index.php try { $con = new PDO('mysql:host=mysql;dbname=db_test', 'fhzbuser', 'fhzbPwd!23_'); $con->query('SET NAMES UTF8'); $res = $con->query('select * from t_test'); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { echo "id:{$row['id']}, title:{$row['title']}"; } } catch (PDOException $e) { echo $e->getMessage(); }
#拉取鏡像
docker pull redis:latest
#如今本地建立redis.conf文件並設置密碼,不然-v redis.conf會自動建立爲目錄
mkdir -p /docker/conf/redis/
echo "requirepass 123" > /docker/conf/redis/redis.conf
#運行實例並指定配置文件
docker run -d -p 6379:6379 -v /docker/conf/redis/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data --name test_redis redis:latest redis-server /etc/redis/redis.conf --appendonly yes
#查看redis的IP地址
docker inspect test_redis
#打開redis-cli模式
docker run -it redis:latest redis-cli -h 172.17.0.5github
#在瀏覽器打開服務器IP地址並訪問網站redis
http://ipsql
rinetd端口映射教程:https://help.aliyun.com/document_detail/43850.html
#下載rinetd
wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz&&cd rinetd
#修改端口號
sed -i 's/65536/65535/g' rinetd.c
#安裝rinetd
mkdir /usr/man&&make&&make install
#編輯配置文件,加入端口轉發規則
vi /etc/rinetd.conf
0.0.0.0 6399 127.0.0.1 6379
0.0.0.0 3366 127.0.0.1 3306
#重啓rinetd
pkill rinetd&&rinetd
#查看設置是否生效
netstat -anp | grep 6399docker
使用Nginx的官方Docker鏡像,啓動容器後沒法顯示本身網站頁面,總顯示Nginx官方默認頁面的問題的解決方法 (http://blog.csdn.net/zhangchao19890805/article/details/77802811)
搜索可用docker鏡像 (http://www.docker.org.cn/book/docker/docker-search-image-6.html)
基於Docker搭建LNMP環境 (http://blog.csdn.net/xy752068432/article/details/75975065)
Docker搭建可一鍵部署的多域名LNMP環境 (https://www.awaimai.com/2120.html)
Docker多容器部署LNMP環境 (http://www.jianshu.com/p/fcd0e542a6b2)
Docker多容器搭建應用棧(lnmp) (http://www.jianshu.com/p/f244eb57820c)
Docker簡介以及使用docker搭建lnmp的過程(多PHP版本) (https://www.cnblogs.com/LO-gin/p/6958720.html)
使用dockerfile 部署lnmpr環境 (https://segmentfault.com/a/1190000009009661)
利用docker搭建php7和nginx運行環境全過程 (http://www.jb51.net/article/113296.htm)
docker安裝redis 指定配置文件且設置了密碼 (https://www.cnblogs.com/cgpei/p/7151612.html)
版權聲明:本文采用署名-非商業性使用-相同方式共享(CC BY-NC-SA 3.0 CN)國際許可協議進行許可,轉載請註明做者及出處。 |