1, Operation on the main server: complete the installation of docker; omitted
2, View image
[root@localhost ~]#docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos/shop2.web.top latest 8fc9b211671a 14 minutes ago 1.835 GB .....
3, Running image and installing nginx environment in image
1,docker run -it -p 10888:8888 -p 10222:22 -p 8081:80 --name centos/shop2.web.top
2. If you use the - d background parameter, use docker exec -it... To enter docker
#/etc/init.d/php-fpm-54 start #/Etc / init.d/ssh d start #/etc/init.d/bt start [start it to access 80]
3. Configure pagoda nginx and do not install mysql. Because MySQL often has data changes, and it is difficult to install the docker mysql image. Please install MySQL on a server other than docker.
4. Configuration of shop2 in docker:
Log in to http://103.15.104.*:10888/login Go to the inside of the pagoda, or enter the container docker exec -it [container id] /bin/bash. Configure
5. Nginx configuration file:
# vi /www/server/nginx/conf/nginx.conf [root@8825f8263497 /]# cat /www/server/nginx/conf/nginx.conf user www www; worker_processes auto; error_log /www/wwwlogs/nginx_error.log crit; pid /www/server/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; include proxy.conf; default_type application/octet-stream; server_names_hash_bucket_size 512; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m; server_tokens off; access_log off; server { listen 888; server_name www.bt.cn; index index.html index.htm index.php; root /www/server/phpmyadmin; #error_page 404 /404.html; include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /www/wwwlogs/access.log; } server { listen 8082; server_name 127.0.0.1; #This is very important. You can visit http://172.17.0.4:80 outside the docker container. index index.html index.htm index.php; root /www/wwwroot/shop; #error_page 404 /404.html; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ .php($|/) { set $script $uri; set $path_info ""; if ($uri ~ "^(.+.php)(/.+)") { set $script $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$script; fastcgi_param SCRIPT_NAME $script; fastcgi_param PATH_INFO $path_info; try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi-54.sock; fastcgi_index index.php; include fastcgi.conf; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /www/wwwlogs/access.log; } include /www/server/panel/vhost/nginx/*.conf; }
4. Configure nginx in the container, and then nginx reload. visit the site
[root@8825f8263497 /]# curl http://127.0.0.1:8082 [the result is right, save... ]
4. Main server configuration environment and access site:
1. cd /usr/local/tengine2/conf / [I use Tengine]
2. Add the following configuration to nginx.conf file
server { listen 80; server_name web.top; error_log logs/shop2.web.log; location / { [The key is that this agent will request web.top:80 Agreement to web.top] proxy_buffering off; proxy_pass http://172.17.0.4:8082; [172.17.0.4 is the ip address of the container] } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
3. Restart nginx
#ps -ef | grep nginx root 18687 1 0 Feb21 ? 00:00:00 nginx: master process ./nginx
#kill -9 18687
#./sbin/nginx
Note: if you use kill nginx, the nginx in the docker container will also be killed.
4. Complete. curl http://web.top [tested successful]
Remarks: 1. View the ip address of the container
docker inspect --format='{{.NetworkSettings.IPAddress}}' $(docker ps -a -q) 2. View the name of the container
sudo docker inspect -f='{{.Name}}' $(sudo docker ps -a -q)