docker的安装以及docker中nginx配置

机器 test3 192.168.23.103

1机器初始化配置

1.1关闭防火墙,清空防火墙规则

systemctl stop firewalld
iptables -F
setenforce 0

1.2部署时间同步

yum install ntp ntpdate -y

1.3安装基础软件包

yum install -y wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack

1.4构建docker-ce源

https://developer.aliyun.com/mirror/
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
yum -y install docker-ce
1.5启动docker
systemctl  restart docker && systemctl enable docker

2.docker的配置

2.1要是想要docker能被其他服务器访问,要是想要docker相互之间通信没有问题,需要修改内核参数,开启包转发功能,内核参数修改,br_netfilter 模块用于将桥接流量转发至iptables链,
[root@test3 ~]# modprobe br_netfilter
模块可以通过这个命令看有没有开启
[root@test3 ~]# lsmod |grep br_netfilter
br_netfilter           22256  0 
bridge                151336  1 br_netfilter[root@test3 ~]# cat > /etc/sysctl.d/docker.conf << EOF
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1 
> net.ipv4.ip_forward = 1
> EOF
具体功能如下
Docker 安装后出现:WARNING: bridge-nf-call-iptables is disabled 的解决办法: 
net.bridge.bridge-nf-call-ip6tables = 1 
net.bridge.bridge-nf-call-iptables = 1net.ipv4.ip_forward = 1: 
将 Linux 系统作为路由或者 VPN 服务就必须要开启 IP 转发功能。当 linux 主机有多个网卡时一个网卡收
到的信息是否能够传递给其他的网卡 ,如果设置成 1 的话 可以进行数据包转发,可以实现 VxLAN 等功
能。不开启会导致 docker 部署应用无法访问。使模块生效
[root@test3 ~]#  sysctl -p /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1重启后模块失效,下面是开机自动加载模块的脚本 
在/etc/新建 rc.sysinit 文件 
cat /etc/rc.sysinit 
#!/bin/bash 
for file in /etc/sysconfig/modules/*.modules ; do 
[ -x $file ] && $file 
donecat /etc/sysconfig/modules/br_netfilter.modules 
modprobe br_netfilter 增加权限
chmod 755 /etc/sysconfig/modules/br_netfilter.modules这样即使重启也会加载模块 

配置阿里云镜像加速器地址

https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 

在这里插入图片描述

docker镜像相关的操作

从dockerhub上查找镜像
[root@test3 ~]# docker search centos
NAME                               DESCRIPTION                                     STARS     OFFICIAL
centos                             DEPRECATED; The official build of CentOS.       7721      [OK]
kasmweb/centos-7-desktop           CentOS 7 desktop for Kasm Workspaces            43        
bitnami/centos-base-buildpack      Centos base compilation image                   0         
dokken/centos-7                    CentOS 7 image for kitchen-dokken               10        
dokken/centos-8                    CentOS 8 image for kitchen-dokken               6         
spack/centos7                      CentOS 7 with Spack preinstalled                2         
dokken/centos-6                    EOL: CentOS 6 image for kitchen-dokken          0         
atlas/centos7-atlasos              ATLAS CentOS 7 Software Development OS          3         
ustclug/centos                     Official CentOS Image with USTC Mirror          0         
spack/centos6                      CentOS 6 with Spack preinstalled                1         
dokken/centos-stream-8                                                             5         
eclipse/centos_jdk8                CentOS, JDK8, Maven 3, git, curl, nmap, mc, …   5         
dokken/centos-stream-9                                                             10        
corpusops/centos-bare              https://github.com/corpusops/docker-images/     0         
corpusops/centos                   centos corpusops baseimage                      0         
eclipse/centos_go                  Centos + Go                                     0         
spack/centos-stream                                                                2         
fnndsc/centos-python3              Source for a slim Centos-based Python3 image…   0         
eclipse/centos_spring_boot         Spring boot ready image based on CentOS         0         
openmicroscopy/centos-systemd-ip   centos/systemd with iproute, for testing mul…   0         
eclipse/centos                     CentOS based minimal stack with only git and…   1         
eclipse/centos_nodejs              CentOS based nodejs4 stack                      0         
eclipse/centos_vertx               CentOS + vertx                                  0         
eclipse/centos_wildfly_swarm       CentOS, WildFly, Swarm                          0         
dockette/centos                    My Custom CentOS Dockerfiles                    1         解释说明
NAME: 镜像仓库的名称
DESCRIPTION:镜像的描述
STARS:类似 github 里面的star,表示点赞,喜欢的意思
OFFICIAL:是否 docker 官方发布

拉取镜像

[root@test3 ~]# docker pull centos

查看有哪些镜像

[root@test3 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
centos       latest    5d0da3dc9764   2 years ago   231MB

把镜像做成离线压缩包

[root@test3 ~]# ls
anaconda-ks.cfg
[root@test3 ~]# docker save -o centos.tar.gz centos
[root@test3 ~]# ls
anaconda-ks.cfg  centos.tar.gz

解压

[root@test3 ~]# docker load -i centos.tar.gz 
Loaded image: centos:latest

删除镜像

docker rmi -f centos:latest

容器相关的操作

以交互式启动并运行容器
[root@test3 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
centos       latest    5d0da3dc9764   2 years ago   231MB
[root@test3 ~]# docker run --name=hello -it centos /bin/bash
[root@573ed31d77d8 /]# #docker run 运行并创建容器
--name 容器的名字
-i 交互式
-t 分配终端
centos:启动docker 需要的镜像
bin/bash 说明你的shell 类型为bash   bash是一种最常用的shell 是大多数 linux 发行版默认的shell 此外还有 c shell 等其他的shell#在起一个终端看一下   docker ps 是查看正在运行的容器
[root@test3 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
573ed31d77d8   centos    "/bin/bash"   6 seconds ago   Up 5 seconds             hello
CONTAINER ID:容器的idIMAGE:容器使用的镜像COMMAND:容器运行的命令STATUS:容器启动的时间PORTS : 容器的名字#以守护式进程方式启动容器
[root@test3 ~]# docker run --name=hello1 -itd centos /bin/bash
ae2fe03e778aa2fbd0b9ba2ac412ff3b2f17eaf04772028e1ab4670fd9bdd7fe
d 表示后台运行#进入hello1的容器
[root@test3 ~]# docker exec -it hello1 /bin/bash
[root@ae2fe03e778a /]# #我们退出会发现 容器他依然运行
[root@test3 ~]# docker exec -it hello1 /bin/bash
[root@ae2fe03e778a /]# exit
exit
[root@test3 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
ae2fe03e778a   centos    "/bin/bash"   3 minutes ago   Up 3 minutes             hello1
[root@test3 ~]# docker ps 会列出正在运行的容器
docker ps -a 会列出正在运行的和已经停止的容器全部都列出来#查看容器日志
[root@test3 ~]# docker logs hello1
[root@test3 ~]# 运行和停止容器
[root@test3 ~]# docker stop hello1
hello1
[root@test3 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@test3 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
ae2fe03e778a   centos    "/bin/bash"   7 minutes ago    Exited (0) 8 seconds ago             hello1
573ed31d77d8   centos    "/bin/bash"   26 minutes ago   Exited (0) 8 minutes ago             hello
[root@test3 ~]# docker start hello1
hello1
[root@test3 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
ae2fe03e778a   centos    "/bin/bash"   8 minutes ago   Up 2 seconds             hello1
[root@test3 ~]# docker rm -f hello
hello
[root@test3 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS          PORTS     NAMES
ae2fe03e778a   centos    "/bin/bash"   8 minutes ago   Up 48 seconds             hello1

docker部署nginx

[root@test3 ~]# docker run --name nginx -p 80 -itd centos
3bd4aa598dd007dc8aba6f43f67d9bd5610e885b724910679edb2694325c8a78
-p 把容器断端口 随机在物理机映射一个端口#进入容器
[root@test3 ~]# docker exec -it nginx /bin/bash
[root@3bd4aa598dd0 /]# 
#此时安装你会发现他会报错
[root@3bd4aa598dd0 /]# yum install wget
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                                                                                                                                                         78  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
[root@3bd4aa598dd0 /]# #解决,删除/etc/yum.repos.d/所有文件,把阿里云的镜像重写进去
[root@3bd4aa598dd0 /]# rm -rf /etc/yum.repos.d/* 
[root@3bd4aa598dd0 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  25202      0 --:--:-- --:--:-- --:--:-- 25202#此时下载就可以了
[root@3bd4aa598dd0 yum.repos.d]# yum install nginx vim -y
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                                                                                       1.2 MB/s | 4.6 MB     00:03    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                                                                                      64 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                                                                                  2.1 MB/s | 8.4 MB     00:04    
Dependencies resolved.
==================================================================================================================================================================================================================Package                                                  Architecture                        Version                                                                Repository                              Size
==================================================================================================================================================================================================================
Installing:nginx                                                    x86_64                              1:1.14.1-9.module_el8.0.0+184+e34fea82                                 AppStream                              570 k
Upgrading:#在容器里更改配置文件,重启nginx
[root@3bd4aa598dd0 yum.repos.d]# echo 'docker is nginx' > /usr/share/nginx/html/index.html 
[root@3bd4aa598dd0 yum.repos.d]# /usr/sbin/nginx          #在宿主机上通过 docker ps 可以查看把容器的 80 端口映射到宿主机的那个端口上,可以看出映射到宿主机的32768端口
[root@test3 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED        STATUS        PORTS                                     NAMES
3bd4aa598dd0   centos    "/bin/bash"   23 hours ago   Up 23 hours   0.0.0.0:32768->80/tcp, :::32768->80/tcp   nginx#访问测试,或者直接请求容器的ip也行
[root@test3 ~]# curl 127.0.0.1:32768
docker is nginx
[root@test3 ~]# curl 172.17.0.3
docker is nginx#流量走向
访问物理节点ip:port(容器在物理节点映射的端口) ——>   容器 ip:port (容器里部署的服务器端口) ——> 就可以访问到容器里部署的应用了

直接运行nginx

[root@test3 ~]# docker pull nginx 
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest#运行nginx
[root@test3 ~]# docker run -d -p 28877:80 nginx
0c0313595bf4632610ae2692a7d8b1efd6321b996c61209d0e8e9f9493881a92-p 28877:80 将宿主机的 28877端口映射到容器的80端口上指定版本# 查询centos镜像版本,也可以在浏览器上访问,看看有哪些版本
curl -s https://registry.hub.docker.com/v1/repositories/centos/tags  |   jq# 领导让你 基于mysql5.7 部署个镜像curl -s https://registry.hub.docker.com/v1/repositories/mysql/tags  |   jq#查看容器ip
[root@test3 ~]# docker inspect nginx|grep IPAddress"SecondaryIPAddresses": null,"IPAddress": "172.17.0.3","IPAddress": "172.17.0.3",

对外访问nginx1.19.7,直接访问宿主机的80端口就能看到nginx

[root@test3 ~]# docker pull nginx:1.19.7
1.19.7: Pulling from library/nginx
45b42c59be33: Pull complete 
8acc495f1d91: Pull complete 
ec3bd7de90d7: Pull complete 
19e2441aeeab: Pull complete 
f5a38c5f8d4e: Pull complete 
83500d851118: Pull complete 
Digest: sha256:f3693fe50d5b1df1ecd315d54813a77afd56b0245a404055a946574deb6b34fc
Status: Downloaded newer image for nginx:1.19.7
docker.io/library/nginx:1.19.7
[root@test3 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    605c77e624dd   2 years ago   141MB
centos       latest    5d0da3dc9764   2 years ago   231MB
nginx        1.19.7    35c43ace9216   3 years ago   133MB
[root@test3 ~]# netstat -tunlp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6937/nginx: master  
[root@test3 ~]# systemctl stop nginx
[root@test3 ~]# netstat -tunlp|grep 80
[root@test3 ~]# docker run -d -p 80:80 35c43ace9216
474c65449759c39c108f020bbe54c37f781620b9968f22f0896427dc597a3585#批量停止正在运行中的容器
[root@test3 ~]# docker ps -q
474c65449759
0c0313595bf4
3bd4aa598dd0
[root@test3 ~]# docker stop $(docker ps -q)
474c65449759
0c0313595bf4
3bd4aa598dd0

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/1604.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

读《零基础学PYthon》有感

前言&#xff1a; 2023年&#xff0c;网络安全竞赛上看见大学同学用python解出了一个谜题&#xff0c;意气风发的我也决心花钱买书把python系统的学习一遍。 结果事与愿违&#xff0c;自己抑郁了半年&#xff0c;再加上繁杂的工作让我不得不放弃计划。今年&#xff0c;我基本能…

测试的面试题

测试问题 什么是测试? 测试在生活中处处可见。 我个人认为测试尝试以达到自己期望的状态 1.2为什么需要软件测试 企业为何需要招聘大量的测试人员呢&#xff1f; 额外的花费额外的时间 企业最终的目的是“盈利” 受众群体主要是广大的使用用户&#xff0c;而用户的使用…

【webrtc】m98 RoundRobinPacketQueue的优先级处理

m98 代码 PacedSender::EnqueuePackets 的调用者可能是多个地方,所以这个要加锁保护。RoundRobinPacketQueue 本身是没有锁的发现m98和新版本不同,参考:【webrtc】m114自己实现的PrioritizedPacketQueuepush和pop都是RtpPacketToSend 但是实际上,内部是封装为QueuedPacket 处…

基于Springboot的人职匹配推荐系统

基于SpringbootVue的人职匹配推荐系统的设计与实现 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringbootMybatis工具&#xff1a;IDEA、Maven、Navicat 系统展示 用户登录 首页 企业信息 岗位信息 新闻资讯 后台管理 用户管理 企业信息管理 岗位信…

Docker之注册中心的使用与操作

一、Docker注册中心与仓库 Reastry 可译为注册中心或注册服务器&#xff0c;是存放仓库的地方&#xff0c;一个注册中心往往有很多仓库。Docker默认的注册中心是Docker Hub&#xff0c;其可以通过浏览器访问&#xff0c;也可以使用docker search命令访问。 仓库是集中存放镜像…

html2Canvas截图包含滚动条解决思路

概况描述 在项目中使用html2Canvas进行截图时发现无法截取滚动条部分&#xff0c;前端是使用vue2的版本&#xff0c;网上找了很多方式都没效果&#xff0c;冷静思考后&#xff0c;给出解决办法。 解决思路 当我们截取的div容器的宽和高与内部的子容器div的宽和高不一样时&am…

如何写好单片机毕业设计的论文

如何写好单片机毕业设计的论文 引言 单片机毕业设计是大学生在专业课程中的重要组成部分,它不仅要求学生能够独立进行科学研究,还要求学生能够将自己的研究成果进行合理的总结和表达。本文将从选题、论文结构、写作技巧等方面,探讨如何写好单片机毕业设计的论文。 选题 …

Django模型的属性与方法

本节介绍Django模型的属性和方法&#xff0c;以及如何重写之前定义的模型方法等内容。 3.5.1 模型属性 Django模型中最重要的属性就是Manager&#xff0c;它是Django模型和数据库查询操作之间的接口&#xff0c;并且被用作从数据库当中获取实例的途径。如果Django模型中没有…

Web开发之v-model和model-value区别

v-model 和 model-value 是在处理表单数据绑定时使用的不同概念&#xff0c;它们分别服务于不同的目的和场景。 1、v-model 用于实现组件内部的双向数据绑定&#xff0c;特别适用于表单元素和支持双向绑定的自定义组件。语法简洁&#xff0c;可以直接在组件模板中使用&#x…

什么是Java Spring框架?

Java Spring框架是一个开放源代码的J2EE应用程序框架&#xff0c;由Rod Johnson在2002年提出并创建。它的主要目标是解决企业级编程开发中的复杂性&#xff0c;实现敏捷开发。Spring框架是一个轻量级的容器&#xff0c;主要用于管理bean的生命周期。它解决了开发者在J2EE开发中…

JAVA学习笔记27(异常)

1.异常 ​ *异常(Exception) ​ *快捷键 ctrl alt t 选中try - catch ​ *如果进行了异常处理&#xff0c;那么即使出现了异常&#xff0c;程序可以继续执行 1.1 基本概念 ​ *在Java语言中&#xff0c;将程序执行中发生的不正常情况称为"异常"(开发过程中的语…

CVE-2024-21887)Ivanti 远程命令注入漏洞

CVE-2024-21887&#xff09;Ivanti 远程命令注入漏洞 一、漏洞简介 Ivа&#xff4e;ti Cоnnесt Sесurе&#xff08;9.х、22.х&#xff09;和 Ivаnti Pоliсу Sесurе 的 Wеb 组件中存在一个命令注入漏洞&#xff0c;使得经过身份验证的管理员能够发送特别构建…

python scrapy 爬取豆瓣电影top250教程2

文章目录 scrapy top250教程1scrapy pipeline将数据写入数据库下载中间件middleware的使用从下层页面爬取详细电影信息运行代码scrapy top250教程1 python scrapy 爬取豆瓣电影top250教程 scrapy pipeline将数据写入数据库 mysql创建表use test; drop TABLE tb_top_movie

MySQL行格式(row format)

MySQL行格式&#xff08;row format&#xff09; 表的行格式决定了其行的物理存储方式&#xff0c;这反过来又会影响查询和 DML 操作的性能。随着单个磁盘页面容纳更多行&#xff0c;查询和索引查找可以更快地工作&#xff0c;缓冲池中需要的高速缓存内存更少&#xff0c;写出…

Nginx的ssl证书配置

http协议数据传输都是明文的。 https是httpssl&#xff0c;ssl是加密协议&#xff0c;通过证书来加密&#xff0c;安装了证书的网站才会用https来交互。 # 再nginx的配置文件的server这中配置 server {#listen 80;listen 443 ssl; #http默认端口是80&#xff0c; …

爬虫f12跳转和debugger检测

在空白页面的控制台运行解决重定向再复制url到网页 //解决重定向 (() > {window.onbeforeunload ()>{debugger;return false;}})();//构造方法无限debugger (() > {Function.prototype.constructor Function.prototype.constructor;Function.prototype.constructor…

nacos 2022.0.0.0 版本实现负载均衡及集群

一、loadbalancer实现负载均衡 新版本的nacos已经取消了对ribbon的支持&#xff0c;所以不能使用ribbon来实现nacos提供的负载均衡。 但是新版本中我们可以使用loadbalancer实现负载均衡。 二、导入loadbalancer坐标 1、原本的坐标&#xff1a; 在parent的pom.xml中 <p…

Python 学习笔记(十一)—— 异常处理

目录 一、异常简介 二、捕获异常 2.1 捕获特定类型的异常 2.2 捕获多个类型的异常 2.3 捕获所有类型的异常 2.4 使用多个except块处理不同类型的异常 三、异常的传递 3.1 异常在函数内部引发&#xff0c;并在函数外部捕获 3.2 异常在多层函数调用中传递 3.3 异常在类…

耐高温300度锅炉轴承,江苏鲁岳轴承制造的行业标杆

自润滑轴承-产品类型-耐高温轴承-不锈钢轴承-江苏鲁岳轴承制造有限公司。锅炉轴承&#xff0c;耐高温至200度-800度。 江苏鲁岳轴承制造有限公司&#xff0c;一家专注于锅炉轴承和耐高温轴承的研发与生产的企业&#xff0c;致力于为客户提供高质量、高性能的轴承解决方案。其中…

使用 OpenCV 测量物体尺寸

使用 OpenCV 测量物体尺寸 你是否曾经遇到过这样的问题&#xff1a;想要知道计算器的精确尺寸&#xff0c;但手头又没有专业的测量工具&#xff1f;别担心&#xff0c;今天我们就来教大家一个简单又实用的方法&#xff0c;通过一张A4纸就能估算出计算器的宽度和高度&#xff0c…