使用阿里云服务器-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

使用阿里云服务器

简介: 操作步骤

尝试基于ECS快速搭建docker环境

image-20210618223452399

image-20210618223539027

image-20210618223624125

image-20210618223650264

ECS云服务器新手上路

image-20210619103343896

image-20210619103400085

image-20210619103431630

下面尝试部署了一下继恩的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

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

       #

       #location ~ \.php$ {

       #    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

   #

   #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;

   #    location / {

   #        root   html;

   #        index  index.html index.htm;

   #    }

   #}

}

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

这是部署在本地 , 现在开始演示部署到云服务器上

image-20210718003213326

通过ssh把配置文件传进去

image-20210718003244110

从dockerhub上拉取镜像

image-20210718003546820

image-20210718003653954

http://47.106.218.61:8888/


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: