1. 程式人生 > >docker安裝swoole和images上傳

docker安裝swoole和images上傳

docker下php找不到php.ini 安裝swoole

echo phpinfo();找到ini的path:(/usr/local/etc/php )
在裡面的conf.d中建立docker-php-ext-mysqli.ini檔案里加上
extension=swoole.so
------------------------------------------------------------------------------------------------
下載swoole:
http://pecl.php.net/package/swoole
解壓:cd swoole-src-swoole-1.7.6-stable/
phpize 
./configure --enable-async-mysql --with-php-config=/usr/local/bin/php-config
make && make install
------------------------------------------------------------------------------------------------
docker上傳:
1.commit製作映象
2.push上傳
------------------------------------------------------------------------------------------------
docker建立php容器時要把需要暴露的介面寫上
docker run -d -p 9000:9000 -p 9501:9501 --name php7 -v /home/ubuntu/nginx/www:/www php7.2:v1
------------------------------------------------------------------------------------------------
伺服器執行:
$server = new swoole_websocket_server("0.0.0.0", 9501);
$server->on('open', function (swoole_websocket_server $server, $request) {
    echo "server: handshake success with fd{$request->fd}\n";
});

$server->on('message', function (swoole_websocket_server $server, $frame) {
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
    $server->push($frame->fd, "這是伺服器訊息!");
});

$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});
echo 1;
$server->start();
------------------------------------------------------------------------------------------------
網頁執行
var socket = new WebSocket('ws://192.168.176.131:9501/'); 
// 開啟Socket 
socket.onopen = function(event) { 
	// 傳送一個初始化訊息 
	socket.send('我是客戶端並且正在監聽。'); 
	// 監聽訊息 
	socket.onmessage = function(event) {
	 console.log('客戶端接收到一個訊息。',event); 
	 }; 
	 // 監聽Socket的關閉 
	 socket.onclose = function(event) {
	  	console.log('客戶端通知套接字已關閉。',event); 
	 }; 
	 // 關閉Socket.... 
	 //socket.close(); 
 };
 ------------------------------------------------------------------------------------------------
 cat ~/.docker/config.json //檢視login docker倉庫資訊
 docker login registry.cn-hangzhou.aliyuncs.com/stoicer/php

 docker ps -a
 docker commit [CONTAINER ID] [name]:[tag]
 docker images
 sudo docker push registry.cn-hangzhou.aliyuncs.com/stoicer/nginx:1.11.1