安装好的文件位置:

/usr/sbin/nginx:主程序

/etc/nginx:存放配置文件

/usr/share/nginx:存放静态文件

/var/log/nginx:存放日志

其实从上面的根目录文件夹可以知道,Linux系统的配置文件一般放在/etc,日志一般放在/var/log,运行的程序一般放在/usr/sbin或者/usr/bin。

Nginx部署流程:

root@ubuntu:/home/yw1989# docker run -p 80 --name nginx_web1 -i -t ubuntu /bin/bash
root@417a0dbc5500:/# : 进入容器中(先apt-get update不然安装不了nginx)
root@417a0dbc5500:/# apt-get install -y nginx : 安装nginx
root@417a0dbc5500:/# apt-get install -y vim : 安装vim
root@3b1e8b137e4e:/# mkdir -p /var/www/html
root@3b1e8b137e4e:/# cd /var/www/html
root@3b1e8b137e4e:/var/www/html# vim index.html : 编辑静态页面
修改nginx配置文件:
root@417a0dbc5500:/# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
root@3b1e8b137e4e:/usr/share/nginx# cd /etc/nginx
root@3b1e8b137e4e:/etc/nginx# ls
root@417a0dbc5500:/etc/nginx# ls
conf.d koi-utf nginx.conf sites-available uwsgi_params
fastcgi.conf koi-win proxy_params sites-enabled win-utf
fastcgi_params mime.types scgi_params snippets
root@3b1e8b137e4e:/etc/nginx# cd sites-enabled/
root@3b1e8b137e4e:/etc/nginx/sites-enabled# ls
default
root@3b1e8b137e4e:/etc/nginx/sites-enabled# vim default
修改root的值为usr/www/html
切换到根目录:运行nginx,
root@417a0dbc5500:/# ps -ef : 容器里面查看当前进程,nginx已经运行起来了。
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 11:56 pts/0 00:00:00 /bin/bash
root 894 1 0 12:55 ? 00:00:00 nginx: master process nginx
www-data 895 894 0 12:55 ? 00:00:00 nginx: worker process
root 897 1 0 12:56 pts/0 00:00:00 ps -ef 使用ctrl+P ctrl+Q来退出。是容器在后台运行。
$docker ps 查看:
417a0dbc5500 ubuntu "/bin/bash" About an hour ago Up About an hour 0.0.0.0:32768->80/tcp nginx_web1
将容器的80端口映射到主机的32768端口上。
root@ubuntu:/home/yw1989# docker port nginx_web1 :查看容器中端口映射情况
80/tcp -> 0.0.0.0:32768
root@ubuntu:/home/yw1989# docker top nginx_web1 : 查看容器中进程的情况
UID PID PPID C STIME TTY TIME CMD
root 3578 3566 0 03:56 pts/0 00:00:00 /bin/bash
Root 7505 3578 0 04:55 ? 00:00:00 nginx: master process nginx
www-data 7506 7505 0 04:55 ? 00:00:00 nginx: worker process
root@ubuntu:/home/yw1989# curl http://127.0.0.1:32768 :网站成功返回了刚才写的页面,虚拟机中使用http://127.0.0.1:32768/,http://172.17.0.2:80/可以访问,172.17.0.2是容器IP。在自己电脑http://192.168.115.129:32768/也可以访问(192.168.115.129是虚拟机的地址)。
<html>
<head>
<title>fdfdsfdsfdsf</title>
</head> <body> <h1>
hhijhihii
</h1>
</body> </html>
root@ubuntu:/home/yw1989# docker inspect nginx_web1 : 查看容器的ip地址
"NetworkSettings": {
"IPAddress": "172.17.0.2", $docker stop nginx_web : 停止容器 nginx_web1
root@ubuntu:/home/yw1989# docker start -i nginx_web1
root@417a0dbc5500:/# ps -ef : 关闭后停止并没有启动nginx,退出
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:22 pts/0 00:00:00 /bin/bash
root 9 1 0 13:22 pts/0 00:00:00 ps -ef
root@ubuntu:/home/yw1989# docker exec nginx_web1 nginx : 启动nginx
root@ubuntu:/home/yw1989# docker top nginx_web1 : 查看到nginx再次启动了
UID PID PPID C STIME TTY TIME CMD
root 10527 10508 0 05:22 pts/0 00:00:00 /bin/bash
root 10718 10508 0 05:24 ? 00:00:00 nginx: master process nginx
www-data 10719 10718 0 05:24 ? 00:00:00 nginx: worker process root@ubuntu:/home/yw1989# curl http://127.0.0.1:32768 : 访问失败
curl: (7) Failed to connect to 127.0.0.1 port 32768: Connection refused
root@ubuntu:/home/yw1989# docker inspect nginx_web1 : ip地址和端口都变了
"NetworkSettings": {
"IPAddress": "172.17.0.2",
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "32769"
}
]
},
停止一个容器并重新启动,ip地址和端口改变。
查看和删除镜像:
镜像是一种使用联合加载技术层叠的只读文件系统,是容器构建的基石。存储在/var/lib/docker,

root@ubuntu:/# docker info
Docker Root Dir: /var/lib/docker
Containers: 4
Running: 3
Paused: 0
Stopped: 1
Images: 1
Server Version: 18.01.0-ce
Kernel Version: 4.10.0-28-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 971.6MiB
Name: ubuntu

root@ubuntu:/# docker images  : 列出所有的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 0458a4468cbc 6 days ago 112MB
REPOSITORY:镜像所属的仓库名
TAG :镜像的标签名
IMAGE ID :镜像的唯一id,就是镜像的文件名
CREATED :镜像建立的时间
SIZE :镜像的大小 REPOSITORY仓库是一系列镜像的集合,一个仓库包含的是一系列关联的镜像,比如ubuntu就是一个大的仓库,这与docker组件中的仓库(registry)很大区别,组件的仓库提供的是docker镜像的存储服务,REPOSITORY仓库包含了很多registry仓库。 Tag镜像的标签:在仓库中不同的镜像是以tag区分的,REPOSITORY仓库名加上标签名就构成了一个完整了镜像名字,这个镜像的名字就对应一个镜像的id。不同的标签可以对应相同的id名,就是说可以对不同的需求对镜像文件打上不同的标签。
root@ubuntu:/# docker images --no-trunc : 查看完整的id(上面是截断的id)
REPOSITOR TAG IMAGE ID CREATED SIZE
ubuntu latest sha256:0458a4468cbceea0c304de953305b059803f67693bad463dcbe7cce2c91ba670 6 days ago 112MB
没有名字和标签的镜像就是中间层镜像。

yw1989@ubuntu:~$ docker search ubuntu : 查找ubuntu仓库
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 7183 [OK]
dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 159 yw1989@ubuntu:~$ docker search --filter=stars=100 ubuntu :查找星级大于100的
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 7183 [OK]
dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 159 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 130

dokcer3的更多相关文章

随机推荐

  1. 本地测试IIS,Post调用接口

    最近在学习三种调用接口方式,POST,Socket,Webserivce,今天刚写完POST方式所以就分享下,欢迎高手指点. public string strResult = "" ...

  2. 问题:Linux 输入任何命令都显示 -bash: fork: Cannot allocate memory

    应该是某个程序吃掉了所有的内存,只能重启

  3. django中表变更后migrate无效的问题

    问题描述: 已有的model,修改之后,想重新建模,于是将migrations文件夹中除__init__.py之外其他文件都删掉,再次执行以下步骤python manage.py makemigrat ...

  4. Codeforces 895E Eyes Closed(线段树)

    题目链接  Eyes Closed 题意  两个人玩一个游戏,现在有两种操作: 1.两个人格子挑选一个区间,保证两个的区间不相交.在这两个区间里面各选出一个数,交换这两个数. 2.挑选一个区间,求这个 ...

  5. ASP.NET Core 依赖注入基本用法

    ASP.NET Core 依赖注入 ASP.NET Core从框架层对依赖注入提供支持.也就是说,如果你不了解依赖注入,将很难适应 ASP.NET Core的开发模式.本文将介绍依赖注入的基本概念,并 ...

  6. ES6之Array.includes()函数

    一.定义 includes() 方法用来判断一个数组是否包含一个指定的值,如果是返回 true,否则false. 二.语法 arr.includes(searchElement) arr.includ ...

  7. Springboot 集成 Thymeleaf 及常见错误

    Thymeleaf模板引擎是springboot中默认配置,与freemarker相似,可以完全取代jsp,在springboot中,它的默认路径是src/main/resources/templat ...

  8. bootstrap-datetimepicker时间控件的使用

    官方文档:http://www.bootcss.com/p/bootstrap-datetimepicker/demo.htm 常规使用: <div class="input-grou ...

  9. 邁向IT專家成功之路的三十則鐵律 鐵律二十二:IT人升遷之道-無為

    升遷管道是許多人求職時相當重要的考量之一,畢竟人除了很愛錢之外更愛顯赫的頭銜,然而在企業中越顯赫的頭銜,其背後通常有更多的罵名,因為許多人的高官厚爵都是踩著一群人的頭頂爬上去的,隨時哪一天跌了下來,都 ...

  10. 【android】getDimension()、getDimensionPixelOffset()和getDimensionPixelSize()区别详解

    在自定义控件中使用自定义属性时,经常需要使用java代码获取在xml中定义的尺寸,相关有以下三个函数 getDimension() getDimensionPixelOffset() getDimen ...