Ubuntu安装docker,并配置一个简易的nginx网页

先ssh连接到虚拟机Ubuntu系统(cmd里面直接连接,也可以借助ssh连接软件):

ssh 用户名@ip地址

然后进入管理员权限下;

sudo su
//然后输入password

然后依次输入执行(install docker):

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo apt install software-properties-common

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
//这句可以合并为一句执行

$ sudo apt-get update

$ apt-cache policy docker-ce

$ sudo apt-get install -y docker-ce

$ sudo systemctl status docker
//输入这句命令如果有显示running就表示成功(下图)

接下来 add docker access right...

$ sudo usermod -aG docker $(whoami) 

>> verify, 要登出再登入,才会有权限

docker ps

> check group belongs to

id -nG

由于我系统是Ubuntu20版本以上就不需要再装python

直接安装compose(Installing Docker Compose)

$ sudo apt-get install python3-pip

$ sudo pip3 install docker-compose

安装之后重启以下虚拟机

** 如果安装过程有错,必须升级 pip3 ,就用以下的命令

error : No module named 'setuptools_rust'

Upgrade to the latest pip and try again. This will fix errors for most

---

》使用 docker 安装 nginx 、配置一个建议的nginx

$ docker run -it --name demo-nginx -p 8080:80 -v /home/demo/nginx:/usr/share/nginx/html:ro -d nginx 


//demo-nginx的demo代表的是你这个nginx的名字,可以自己起名字的,往后配置其他nginx后面的路径名也改成其他的

/home/demo/nginx  这个路径名要记得,待会后面配置默认nginx网页时要在这个目录底下创建index.html

然后查看刚才的run的id

$ docker ps -a

 开启这个nginx项目服务

$ docker container start 你的id

然后我们进入刚才那个nginx的目录下编写一个index.html文件让其具有一个默认网页。

$ cd /home/demo/nginx

$ sudo vi index.html

按i进行编辑(vim命令)
<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

the docker nginx is OK!

<h2>Add more information</h2>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>

</body>

</html>


按Esc键,按:键,输入wq(保存退出)

这时候我们的docker的一个nginx就可以访问到了。我们去宿主机浏览器输入ip:8080(这个端口是刚才run的哪一行命令里面有指定的,代表的是docker外面的访问端口),看到下图即表示成功了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值