天天看點

使用阿裡雲伺服器

嘗試基于ECS快速搭建docker環境

ECS雲伺服器新手上路

下面嘗試部署了一下繼恩的vue和nginx

nginx使用挂載的方式-v 來實作對容器内部nginx配置檔案的替換,

利用docker cp 來把dist檔案拷貝進去

使用-p 的方式替換端口

root@yourtreedad:~# docker pull nginx

Using default tag: latest

latest: Pulling from library/nginx

b4d181a07f80: Already exists

66b1c490df3f: Pull complete

d0f91ae9b44c: Pull complete

baf987068537: Pull complete

6bbc76cbebeb: Pull complete

32b766478bc2: Pull complete

Digest: sha256:353c20f74d9b6aee359f30e8e4f69c3d7eaea2f610681c4a95849a2fd7c497f9

Status: Downloaded newer image for nginx:latest

docker.io/library/nginx:latest

root@yourtreedad:~#

root@yourtreedad:~# docker images

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE

nginx                    latest              4cdc5dd7eaad        10 days ago         133MB

yourtreedad/blazordemo   latest              aa1397c0af05        2 weeks ago         207MB

mysql                    latest              5c62e459e087        3 weeks ago         556MB

root@yourtreedad:~# cd ..

root@yourtreedad:/# pwd

/

root@yourtreedad:/# cd home

root@yourtreedad:/home# ls

blazortest    haierDemo  ljs      mvcwindowstest  nginx      tomcat

consoletest1  kuangshen  mvctest  mysql           nginxdemo  webapitest

root@yourtreedad:/home# cd nginxdemo

root@yourtreedad:/home/nginxdemo# ls

nginx-1.14.2  nginx-1.14.2.zip

root@yourtreedad:/home/nginxdemo# cd nginx-1.14.2

root@yourtreedad:/home/nginxdemo/nginx-1.14.2# ls

conf  contrib  dist  docs  html  logs  nginx.exe  temp

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker run --name nginxdemo2 -p 8889:8765 -v /home/nginxdemo/nginx-1

.14.2/conf/myconf1.conf:/etc/nginx/nginx.conf:ro -d nginx

6bed1ace8c9942f62e61ea18f7f632973fa1d7536ac3a6d1ada11e3d2c093b6e

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker cp /home/nginxdemo/nginx-1.14.2/dist 6bed1ace8c9942f62e:/etc/nginx

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker exec -it 6bed1ace8c9942f62e61ea18f7f632973fa1d7536ac3a6d1ada11e3d2c093b6e /bin/bash

ls

root@6bed1ace8c99:/# ls

bin   docker-entrypoint.d   home   media  proc  sbin  tmp

boot  docker-entrypoint.sh  lib    mnt    root  srv   usr

dev   etc                   lib64  opt    run   sys   var

root@6bed1ace8c99:/# cd /etc

root@6bed1ace8c99:/etc# cd nginx

root@6bed1ace8c99:/etc/nginx# ls

conf.d  dist  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params

root@6bed1ace8c99:/etc/nginx# cat nginx.conf

#user  nobody;

c553c6ba5f13: Pushed

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

Head

https://registry-1.docker.io/v2/yourtreedad/nginxcontaindist/blobs/sha256:4d7903a7ce4bdf92461e0dd87d1fb712facb6881df3cbce68f55f4ec54791546:

dial tcp: lookup registry-1.docker.io on 192.168.65.5:53: no such host

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf#

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type  application/octet-stream;

   #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

   #                  '$status $body_bytes_sent "$http_referer" '

   #                  '"$http_user_agent" "$http_x_forwarded_for"';

   #access_log  logs/access.log  main;

   # server {

   #     listen 8765;

   #     listen localhost;

   #     location / {

   #         root dist;

   #         index index.html index.htm;

   #     }

   # }

   sendfile        on;

   #tcp_nopush     on;

   #keepalive_timeout  0;

   keepalive_timeout  65;

   #gzip  on;

   server {

       listen       8765;

       server_name  localhost;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {

           root   dist;

           index  index.html index.htm;

       }

       #error_page  404              /404.html;

       # redirect server error pages to the static page /50x.html

       #

       error_page   500 502 503 504  /50x.html;

       location = /50x.html {

           root   html;

       # proxy the PHP scripts to Apache listening on 127.0.0.1:80

       #location ~ \.php$ {

       #    proxy_pass  

http://127.0.0.1;

       #}

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

       #    root           html;

       #    fastcgi_pass   127.0.0.1:9000;

       #    fastcgi_index  index.php;

       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

       #    include        fastcgi_params;

       #}

67f2e8eb8c87: Pushing [>                                                  ]  77.82kB/4.758MB

       # concurs with nginx's one

       #location ~ /\.ht {

       #    deny  all;

   }

   # another virtual host using mix of IP-, name-, and port-based configuration

   #

   #server {

   #    listen       8000;

   #    listen       somename:8080;

   #    server_name  somename  alias  another.alias;

   #    location / {

   #        root   html;

   #        index  index.html index.htm;

   #    }

   #}

   # HTTPS server

   #    listen       443 ssl;

   #    server_name  localhost;

   #    ssl_certificate      cert.pem;

   #    ssl_certificate_key  cert.key;

   #    ssl_session_cache    shared:SSL:1m;

   #    ssl_session_timeout  5m;

   #    ssl_ciphers  HIGH:!aNULL:!MD5;

   #    ssl_prefer_server_ciphers  on;

root@6bed1ace8c99:/etc/nginx# exit

exit

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker commit -a="yourtreedad" -m="jien's ui add ljs's deploy new nginx that contains dist" 6bed1ace8c nginx:1.0

sha256:4d7903a7ce4bdf92461e0dd87d1fb712facb6881df3cbce68f55f4ec54791546

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker push yourtreedad/nginx:1.0

The push refers to repository [docker.io/yourtreedad/nginx]

An image does not exist locally with the tag: yourtreedad/nginx

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker tag nginx:1.0 yourtreedad/nginxcontaindist:1.0

root@yourtreedad:/home/nginxdemo/nginx-1.14.2/conf# docker push yourtreedad/nginxcontaindist:1.0

The push refers to repository [docker.io/yourtreedad/nginxcontaindist]

67f2e8eb8c87: Preparing

9d1af766c818: Preparing

d97733c0a3b6: Preparing

c553c6ba5f13: Preparing

48b4a40de359: Preparing

ace9ed9bcfaf: Waiting

764055ebc9a7: Waiting

這是部署在本地 , 現在開始示範部署到雲伺服器上

通過ssh把配置檔案傳進去

從dockerhub上拉取鏡像

http://47.106.218.61:8888/