docker安装并修改Nginx镜像
1、安装nginx镜像,命令:docker pull nginx
2、创建nginx容器,并启动,命令:docker run --name webserver -d -p 192.168.51.227:9999:80 nginx
run = create容器+start容器;
--name:指定容器的名字;
-d:后台运行;
-p:使用 -p 参数时,可以指定要映射的端口,并且在一个指定的端口上只可以绑定一个容器。支持的格式有:
- IP:HostPort:ContainerPort
- IP:ContainerPort
- HostPort:ContainerPort
nginx:要创建容器使用的镜像
注:-p参数端口映射,不指定IP可能远程无法访问。
3、查看启动中的容器的信息,命令:docker ps
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd6957191c52 nginx "nginx -g 'daemon ..." minutes ago Up minutes 192.168.51.227:->/tcp webserver
4、查看容器端口映射相关信息,命令:docker port webserver
[root@localhost nginx]# docker port webserver
/tcp -> 192.168.51.227:
5、查看容器详细信息,命令:docker inspect cd6957191c52
[root@localhost nginx]# docker inspect cd6957191c52
[
{
"Id": "cd6957191c52b25d29319b8ad450313931f2a8c730e4f1052704be957f8c573d",
"Created": "2018-06-01T01:06:34.089549987Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": ,
"ExitCode": ,
"Error": "",
"StartedAt": "2018-06-01T01:06:34.307275905Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:ae513a47849c895a155ddfb868d6ba247f60240ec8495482eca74c4a2c13a881",
"ResolvConfPath": "/var/lib/docker/containers/cd6957191c52b25d29319b8ad450313931f2a8c730e4f1052704be957f8c573d/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/cd6957191c52b25d29319b8ad450313931f2a8c730e4f1052704be957f8c573d/hostname",
"HostsPath": "/var/lib/docker/containers/cd6957191c52b25d29319b8ad450313931f2a8c730e4f1052704be957f8c573d/hosts",
"LogPath": "",
"Name": "/webserver",
"RestartCount": ,
"Driver": "overlay2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "192.168.51.227",
"HostPort": ""
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount":
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": ,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": ,
"Runtime": "docker-runc",
"ConsoleSize": [
, ],
"Isolation": "",
"CpuShares": ,
"Memory": ,
"NanoCpus": ,
"CgroupParent": "",
"BlkioWeight": ,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": ,
"CpuQuota": ,
"CpuRealtimePeriod": ,
"CpuRealtimeRuntime": ,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": ,
"KernelMemory": ,
"MemoryReservation": ,
"MemorySwap": ,
"MemorySwappiness": -,
"OomKillDisable": false,
"PidsLimit": ,
"Ulimits": null,
"CpuCount": ,
"CpuPercent": ,
"IOMaximumIOps": ,
"IOMaximumBandwidth":
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/d398ea082f4d98f4c42a66576114d08741846ff5ed42dc7630d28467d0df7e5d-init/diff:/var/lib/docker/overlay2/7b46becc5c07932a491ba03fa4a63cdcfa82c3939565109ec042123212355eb9/diff:/var/lib/docker/overlay2/7f407789f9c68b0b99591d4fdce67e3a13fb8a88d70a5c86aae4ef0ed41ca577/diff:/var/lib/docker/overlay2/3bb3dbd12f24a463d2c800dbba46b1bccee27557b670396426efff1fdec55539/diff",
"MergedDir": "/var/lib/docker/overlay2/d398ea082f4d98f4c42a66576114d08741846ff5ed42dc7630d28467d0df7e5d/merged",
"UpperDir": "/var/lib/docker/overlay2/d398ea082f4d98f4c42a66576114d08741846ff5ed42dc7630d28467d0df7e5d/diff",
"WorkDir": "/var/lib/docker/overlay2/d398ea082f4d98f4c42a66576114d08741846ff5ed42dc7630d28467d0df7e5d/work"
}
},
"Mounts": [],
"Config": {
"Hostname": "cd6957191c52",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.13.12-1~stretch",
"NJS_VERSION=1.13.12.0.2.0-1~stretch"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c72e2e3656c36f679b1d6db45c36b586b5643acc17f1a429ae7f38525458ae8a",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": ,
"Ports": {
"80/tcp": [
{
"HostIp": "192.168.51.227",
"HostPort": ""
}
]
},
"SandboxKey": "/var/run/docker/netns/c72e2e3656c3",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "f010ca8232a1a8d1054305ecc49bf0d3ca4666b5a9c6b1a2d5b060a209d963d2",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "ec84265a9aadee0c581ebeec22571e0f1c151dd96f0f6bbde7abad7148a0e3ce",
"EndpointID": "f010ca8232a1a8d1054305ecc49bf0d3ca4666b5a9c6b1a2d5b060a209d963d2",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
6、获得容器IP,命令:docker inspect cd6957191c52 |grep IPAddress
[root@localhost nginx]# docker inspect cd6957191c52 |grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
7、访问nginx:http://192.168.51.227:9999/
8、容器的停止,命令:docker stop cd6957191c52
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd6957191c52 nginx "nginx -g 'daemon ..." minutes ago Up minutes 192.168.51.227:->/tcp webserver
[root@localhost nginx]# docker stop cd6957191c52
cd6957191c52
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost nginx]#
9、查看不在运行状态的容器,命令:docker ps -a
[root@localhost nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd6957191c52 nginx "nginx -g 'daemon ..." minutes ago Exited () About a minute ago webserver
10、启动容器,命令:docker start cd6957191c52
11、进入已经创建的容器,命令:docker exec -it cd6957191c52 bash
[root@localhost nginx]# docker start cd6957191c52
cd6957191c52
[root@localhost nginx]# docker exec -it cd6957191c52 /bin/bash
root@cd6957191c52:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@cd6957191c52:/#
12、修改nginx访问页面内容
[root@localhost nginx]# docker exec -it cd6957191c52 bash
root@cd6957191c52:/#
root@cd6957191c52:/#
root@cd6957191c52:/#
root@cd6957191c52:/# echo '<h1>Hello,Docker!</h1>' > /usr/share/nginx/html/index.html
root@cd6957191c52:/# exit
exit
13、刷新页面或者重新访问:http://192.168.51.227:9999/,见下图
14、我们修改了容器的文件,也就是改动了容器的存储层。我们可以通过 docker的diff 命令看到具体的改动,命令如下:docker diff webserver
[root@localhost nginx]# docker diff webserver
C /root
A /root/.bash_history
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/uwsgi_temp
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp
C /usr
C /usr/share
C /usr/share/nginx
C /usr/share/nginx/html
C /usr/share/nginx/html/index.html
C /run
A /run/nginx.pid
A /run/secrets
15、现在我们定制好了变化,我们希望能将其保存下来形成镜像。要知道,当我们运行一个容器的时候(如果不使用卷的话),我们做的任何文件修改都会被记录于容器存储层里。而 Docker 提供了一个 docker commit 命令,可以将容器的存储层保存下来成为镜像。换句话说,就是在原有镜像的基础上,再叠加上容器的存储层,并构成新的镜像。以后我们运行这个新镜像的时候,就会拥有原有容器最后的文件变化。
docker commit 的语法格式为:
docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]
我们可以用下面的命令将容器保存为镜像:docker commit --author "dyh <dyh@126.com>" --message "修改默认网页" webserver nginx:v2
[root@localhost nginx]# docker commit --author "dyh <dyh@126.com>" --message "修改默认网页" webserver nginx:v2
sha256:1eca2575e4f55cac30e2b7f0dbcb719696a0dd8a68c46181c5c7c91205275f12
16、查看镜像信息,命令:docker images nginx
[root@localhost nginx]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v2 1eca2575e4f5 About a minute ago MB
docker.io/nginx latest ae513a47849c weeks ago MB
17、查看镜像内的历史记录,命令:docker history nginx:v2
[root@localhost nginx]# docker history nginx:v2
IMAGE CREATED CREATED BY SIZE COMMENT
1eca2575e4f5 minutes ago nginx -g daemon off; B 修改默认网页
ae513a47849c weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daem... 0 B
<missing> weeks ago /bin/sh -c #(nop) STOPSIGNAL [SIGTERM] B
<missing> weeks ago /bin/sh -c #(nop) EXPOSE /tcp B
<missing> weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/ngi... B
<missing> weeks ago /bin/sh -c set -x && apt-get update && a... 53.7 MB
<missing> weeks ago /bin/sh -c #(nop) ENV NJS_VERSION=1.13.... B
<missing> weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.13.... B
<missing> weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX ... B
<missing> weeks ago /bin/sh -c #(nop) CMD ["bash"] B
<missing> weeks ago /bin/sh -c #(nop) ADD file:ec5be7eec56a749... 55.3 MB
18、使用新的镜像创建容器,命令:docker run --name webserver2 -d -p 192.168.51.227:8888:80 nginx:v2
[root@localhost nginx]# docker run --name webserver2 -d -p 192.168.51.227:: nginx:v2
10af87f7973e9c04e352783521eb0f50bdbd6f3e1de85d2517e3c177977f3e5a
19、查看镜像进程
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10af87f7973e nginx:v2 "nginx -g 'daemon ..." seconds ago Up seconds 192.168.51.227:->/tcp webserver2
cd6957191c52 nginx "nginx -g 'daemon ..." About an hour ago Up minutes 192.168.51.227:->/tcp webserver
20、访问新容器:http://192.168.51.227:8888/
docker安装并修改Nginx镜像的更多相关文章
- docker实战之通过nginx镜像来部署静态页
本章我们主要讲解如何通过docker构建一个nginx容器,这里我们以部署一个静态html为素材来进行演示. 首先我们通过[docker search nginx]命令来查找Docker Hub上的n ...
- Docker 安装并定制 Nginx 服务器
安装并定制 Nginx 1.查阅对应的官方文档,首先下载镜像文件: [spider@izwz9d74k4cznxtxjeeur9z local]$ sudo docker pull nginx [su ...
- docker学习之路-nginx镜像(翻译)
本篇来自https://hub.docker.com/_/nginx/?tab=description 它是docker hub上nginx的官方网站,上面有关于nginx的使用描述等.从这里你可以找 ...
- docker安装与配置nginx详细过程
注:大鸟飞过,此方式只用于快速搭建使用 第一步 pull nginx 命令:docker pull nginx 第二步 启动nginx 命令:docker run --name nginx -p 80 ...
- Docker安装mysql、nginx、redis、tomcat
拉取mysql 5.7官方镜像 docker pull mysql:5.7 启动容器 docker run --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PAS ...
- Docker安装Mysql和Nginx
1. 序言 将应用容器化更方便于管理,昨天辛辛苦苦安装在宿主机上的,今天狠心重置服务器,学下docker练练手. 2. Get start 2.1 安装Docker 公司的云用的是ubuntu,我自己 ...
- docker制作cenos+php56+nginx镜像
首先你环境要安装好docker 1 获取centos镜像. docker search centos 选取第一个官方镜像. docker pull docker.io/centos 新建镜像挂载目录 ...
- Docker for windows修改默认镜像文件位置
docker版本为18.06 windows上安装的docker其实本质上还是借助与windows平台的hyper-v技术来创建一个Linux虚拟机,你执行的所有命令其实都是在这个虚拟机里执行的,所以 ...
- docker安装和配置nginx
配置nginx docker配置nginx 本机ip是192.168.0.200 docker pull nginx 配置nginx主机 vi /root/docker/nginx/nginx01.c ...
随机推荐
- DBA思考系列——学会拒绝不合理的需求
DBA思考系列--学会拒绝不合理的需求 一直以来,个性都比较随意,一般很少拒绝开发人员的一些需求(有点老好人的感觉). 这点一直被老大诟病,也一直在反省!最近又有一件事情,让我觉得:应该学会拒绝不 ...
- python第一百一十一天 --Django 6 model 的相关操作
创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行数据库操作 import MySQLdb def GetList(sql): db ...
- TNS-12535: TNS:operation timed out
AWS数据库云服务器出现了连接超时的错误,于是查看相关时段的alert日志,发现了如下的错误: **************************************************** ...
- 服务器体系(SMP, NUMA, MPP)与共享存储器架构(UMA和NUMA)
1. 3种系统架构与2种存储器共享方式 1.1 架构概述 从系统架构来看,目前的商用服务器大体可以分为三类 对称多处理器结构(SMP:Symmetric Multi-Processor) 非一致存储访 ...
- 关于java中assert(断言)的使用讲解
说明:写的不是很全面,有任何问题请留言,多交流,谢谢! 1.eclipse.myeclipse开启assert(断言),默认是关闭,如下: 说白了就是设置一下jvm的参数,参数是-ea或者-enabl ...
- May 27. 2018 Week 22nd Sunday
All things come to those who wait. 苍天不负有心人. It is said that those who are patient can see what their ...
- servlet温习
servlet是Javaweb的核心,它实质上就是运行在服务器端的Java代码 1.简介 servlet是运行在服务器端的小程序,是sun公司提供的一套规范(接口),用来处理用户的请求,响应给浏览器的 ...
- Thread.currentThread()和this的区别——《Java多线程编程核心技术》
前言:在阅读<Java多线程编程核心技术>过程中,对书中程序代码Thread.currentThread()与this的区别有点混淆,这里记录下来,加深印象与理解. 具体代码如下: pub ...
- 单片机与android手机通信(控制LED小灯亮灭)
1.单片机实验板功能设计 为验证数据通信内容,让单片机板上的四个按键与android手机客户端上的四个LED灯相互控制:为达到上述基本实验要求,采用单字符传输数据即可,硬件需设计两块相同的单片机电路板 ...
- 试验一下Golang 网络爬虫框架gocolly/colly
参考:http://www.cnblogs.com/majianguo/p/8186429.html 框架源码在 github.com/gocolly/colly 代码如下(github源码中的dem ...