目录

数据卷

数据卷容器

端口映射与容器互联

互联机制实现便捷互访(基于容器搭建论坛)


数据卷

1.创建数据卷

[root@openEuler-1 /]# docker volume create test
test
[root@openEuler-1 /]# docker volume ls
DRIVER              VOLUME NAME
local               test
[root@openEuler-1 /]# docker volume inspect test
[{"CreatedAt": "2025-08-23T20:21:27+08:00","Driver": "local","Labels": {},"Mountpoint": "/var/lib/docker/volumes/test/_data","Name": "test","Options": {},"Scope": "local"}
]

2.绑定数据卷

[root@openEuler-1 /]# docker run -d -P --name web -v  /webapp:/opt/webapp nginx:1.17.1
156c0bc3b05a60eb8aac9c8faf6fa6b750830c623c71c8b8cacd02cf6957f8cf
[root@openEuler-1 /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS                   NAMES
156c0bc3b05a        nginx:1.17.1        "nginx -g 'daemon of…"   21 seconds ago      Up 19 seconds                  0.0.0.0:32768->80/tcp   web
bf9f9b03a3e2        ubuntu:18.04        "/bin/bash"              40 minutes ago      Exited (0) 40 minutes ago                              trusting_chatterjee
0cf0f6e06be4        f9a80a55f492        "/bin/bash"              About an hour ago   Exited (0) About an hour ago                           zen_hypatia
db9442307637        f9a80a55f492        "echo 'hello world'"     About an hour ago   Exited (0) About an hour ago                           friendly_benz
3dd062ba408c        f9a80a55f492        "/bin/bash"              About an hour ago   Up About an hour                                       stoic_kilby
b34aa516d411        f9a80a55f492        "echo 111"               About an hour ago   Exited (0) About an hour ago                           pedantic_hugle
04247d9734ba        f9a80a55f492        "echo hello"             About an hour ago   Exited (0) About an hour ago                           gifted_almeida
[root@openEuler-1 /]# ls
afs  bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  webapp
[root@openEuler-1 /]# cd /webapp/
[root@openEuler-1 webapp]# ls
[root@openEuler-1 webapp]# touch test.sh
[root@openEuler-1 webapp]# ls
test.sh
[root@openEuler-1 webapp]# docker exec -it web bash
root@156c0bc3b05a:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@156c0bc3b05a:/# cd opt/
root@156c0bc3b05a:/opt# ls
webapp
root@156c0bc3b05a:/opt# cd webapp/
root@156c0bc3b05a:/opt/webapp# ls
test.sh

数据卷容器

1.首先创建一个数据卷容器

[root@openEuler-1 webapp]# docker run -it -v /dbdata --name dbdata myubuntu:latest
root@f38e5b2b772e:/# ls
bin   dbdata  etc   lib    media  opt   root  sbin  sys  usr
boot  dev     home  lib64  mnt    proc  run   srv   tmp  var

2.使用--volumes-from来挂载容器中的数据卷

[root@openEuler-1 ~]# docker run -it --volumes-from dbdata --name db1 myubuntu:latest
root@c15c195c0ba7:/# ls
bin   dbdata  etc   lib    media  opt   root  sbin  sys  usr
boot  dev     home  lib64  mnt    proc  run   srv   tmp  var
root@c15c195c0ba7:/# cd /dbdata/
root@c15c195c0ba7:/dbdata# echo test1 > test1.txt

3.查看结果

root@f38e5b2b772e:/# cd dbdata/
root@f38e5b2b772e:/dbdata# ls
test1.txt

4.如果删除了挂载的容器,数据卷并不会自动删除,如果想要删除一个数据卷,必须在删除最后一个还挂载的容器时使用docker rm -v 命令来指定删除关联容器。

端口映射与容器互联

[root@openEuler-1 ~]# docker run --name web -d -P  -v  /webapp/:/usr/share/nginx/html nginx:1.17.1
d1b8df54d5fbf7acfcac71a905e7791479028576ffa2c0c1353dde7effde4746
[root@openEuler-1 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES
d1b8df54d5fb        nginx:1.17.1        "nginx -g 'daemon of…"   7 seconds ago       Up 6 seconds        0.0.0.0:32771->80/tcp   web
[root@openEuler-1 ~]# docker run --name web1 -d -p 80:80  -v  /webapp/:/usr/share/nginx/html nginx:1.17.1
acaf3c021bb96f35451d844bac1a04b9ba5d55c777d85eaa93e2b30444b7b076
[root@openEuler-1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                   NAMES
acaf3c021bb9        nginx:1.17.1        "nginx -g 'daemon of…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp      web1
d1b8df54d5fb        nginx:1.17.1        "nginx -g 'daemon of…"   19 minutes ago       Up 19 minutes       0.0.0.0:32771->80/tcp   web
[root@openEuler-1 ~]# docker rm -f web1
web1
[root@openEuler-1 ~]# docker run --name web1 -d -p 192.168.1.11:80:80  -v  /webapp/:/usr/share/nginx/html nginx:1.17.1
4b8886a595c54feb6d6a417465235f71aa9c9e67270f17da4033fd740de8aef9
[root@openEuler-1 ~]# docker rm -f web1
web1
[root@openEuler-1 ~]# docker run --name web1 -d -p 192.168.1.11::80  -v  /webapp/:/usr/share/nginx/html nginx:1.17.1
93ba8e8635fb123d8226c51f70115063640583d69006889f1fca304a7fa27937
[root@openEuler-1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                        NAMES
93ba8e8635fb        nginx:1.17.1        "nginx -g 'daemon of…"   6 seconds ago       Up 5 seconds        192.168.1.11:32768->80/tcp   web1
d1b8df54d5fb        nginx:1.17.1        "nginx -g 'daemon of…"   21 minutes ago      Up 21 minutes       0.0.0.0:32771->80/tcp        web

互联机制实现便捷互访(基于容器搭建论坛)

wordpress使用MySQL数据库,还需进入数据库进行创建

[root@openEuler-1 ~]# docker run --name db -e MYSQL_ROOT_PASSWORD=123456 -d --re                                                                           start=always mysql:5.6
Unable to find image 'mysql:5.6' locally
5.6: Pulling from library/mysql
35b2232c987e: Pull complete
fc55c00e48f2: Pull complete
0030405130e3: Pull complete
e1fef7f6a8d1: Pull complete
1c76272398bb: Pull complete
f57e698171b6: Pull complete
f5b825b269c0: Pull complete
dcb0af686073: Pull complete
27bbfeb886d1: Pull complete
6f70cc868145: Pull complete
1f6637f4600d: Pull complete
Digest: sha256:20575ecebe6216036d25dab5903808211f1e9ba63dc7825ac20cb975e34cfcae
Status: Downloaded newer image for mysql:5.6
c102b94bfd37b6c4142f33b30ca846aafd2aa40b107ba0a4a197654bfd116fef
[root@openEuler-1 ~]# docker run --name bbs -p 80:80 --link db:mysql -d --restar                                                                           t=always wordpress
Unable to find image 'wordpress:latest' locally
latest: Pulling from library/wordpress
396b1da7636e: Pull complete
10b731a0229f: Pull complete
759df4fda9eb: Pull complete
b84170966370: Pull complete
ca765eff712f: Pull complete
71d7acda44c3: Pull complete
aa8657555675: Pull complete
819443c89dcc: Pull complete
05afda0128fe: Pull complete
39fc65577ce1: Pull complete
925278ddd016: Pull complete
5d8fabf0ca99: Pull complete
2e9cb0b67c18: Pull complete
af388e74f0fa: Pull complete
4f4fb700ef54: Pull complete
a9a1a9a7fc0e: Pull complete
e8ecdeb45b2a: Pull complete
23a56f9ae83a: Pull complete
468e488018a8: Pull complete
6a9476a39f47: Pull complete
6d29ea965e3f: Pull complete
7f2e00ef73bc: Pull complete
295267415a53: Pull complete
45cfe8def0e7: Pull complete
Digest: sha256:c5f075fe71c9120e769edbf761bcf20bf0b73d72d49dfde042a06aafcdfef08d
Status: Downloaded newer image for wordpress:latest
f7a1adbef5dbf11ac999b12728be9b11772ef04bf9abb97e3e278bd93136132b
[root@openEuler-1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED                                                                                        STATUS              PORTS                NAMES
f7a1adbef5db        wordpress           "docker-entrypoint.s…"   3 minutes ago                                                                                  Up 3 minutes        0.0.0.0:80->80/tcp   bbs
c102b94bfd37        mysql:5.6           "docker-entrypoint.s…"   9 minutes ago                                                                                  Up 9 minutes        3306/tcp             db
[root@openEuler-1 ~]# docker exec -it bbs bash
root@f7a1adbef5db:/var/www/html# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      mysql c102b94bfd37 db
172.17.0.3      f7a1adbef5db
root@f7a1adbef5db:/var/www/html# env
MYSQL_PORT=tcp://172.17.0.2:3306
MYSQL_PORT_3306_TCP_ADDR=172.17.0.2
MYSQL_NAME=/bbs/mysql
MYSQL_ENV_MYSQL_ROOT_PASSWORD=123456
MYSQL_PORT_3306_TCP_PORT=3306
HOSTNAME=f7a1adbef5db
PHP_VERSION=8.2.29
APACHE_CONFDIR=/etc/apache2
PHP_INI_DIR=/usr/local/etc/php
GPG_KEYS=39B641343D8C104B2B146DC3F9C39DC0B9698544 E60913E4DF209907D8E30D96659A97                                                                           C9CF2A795A 1198C0117593497A5EC5C199286AF1F9897469DC
MYSQL_ENV_MYSQL_MAJOR=5.6
PHP_LDFLAGS=-Wl,-O1 -pie
MYSQL_PORT_3306_TCP=tcp://172.17.0.2:3306
PWD=/var/www/html
HOME=/root
MYSQL_ENV_GOSU_VERSION=1.12
PHP_SHA256=475f991afd2d5b901fb410be407d929bc00c46285d3f439a02c59e8b6fe3589c
PHPIZE_DEPS=autoconf            dpkg-dev                file            g++    g                                                                           cc              libc-dev                make            pkg-config             r                                                                           e2c
TERM=xterm
PHP_URL=https://www.php.net/distributions/php-8.2.29.tar.xz
MYSQL_PORT_3306_TCP_PROTO=tcp
SHLVL=1
PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_                                                                           OFFSET_BITS=64
APACHE_ENVVARS=/etc/apache2/envvars
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PHP_ASC_URL=https://www.php.net/distributions/php-8.2.29.tar.xz.asc
PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FIL                                                                           E_OFFSET_BITS=64
MYSQL_ENV_MYSQL_VERSION=5.6.51-1debian9
_=/usr/bin/env[root@openEuler-1 ~]# docker exec -it db bash
root@c102b94bfd37:/# mysql -uroot -p123456 -e 'create database wordpress'
Warning: Using a password on the command line interface can be insecure.

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

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

相关文章

VSCode Import Cost:5 分钟学会依赖瘦身

一句话作用:在代码里 import 时,实时显示包大小,帮你一眼揪出体积炸弹。1️⃣ 30 秒安装 & 启动 打开 VSCode → 扩展商店搜索 Import Cost → 安装重启 VSCode,立即生效,零配置。2️⃣ 使用方式(开箱即…

TCP/UDP详解(一)

UDP报文源端口16bit 目的端口16bit校验和checksum16bit 总长度16bit--------------------------------------------------------------------------------------------------------------------------源目端口用于标识应用层协议,分为知名端口&#x…

数据库优化提速(一)之进销存库存管理—仙盟创梦IDE

从存储过程到通用 SQL:进销存系统的数据操作优化在进销存系统的开发与维护中,数据库查询语句的编写方式对系统的性能、兼容性和可维护性有着深远影响。本文将围绕给定的三段 SQL 代码展开,深入探讨将存储过程转换为通用 SQL 在进销存场景下的…

Redis面试精讲 Day 28:Redis云原生部署与Kubernetes集成

【Redis面试精讲 Day 28】Redis云原生部署与Kubernetes集成 在当今微服务与容器化浪潮中,Redis作为高性能缓存和消息中间件,已从单机部署逐步演进为云原生环境下的核心组件。Day 28 聚焦“Redis云原生部署与Kubernetes集成”,深入解析如何在…

leetcode刷题记录03——top100题里的6道简单+1道中等题

leetcode刷题记录03——top100题里的6道简单1道中等题上一篇博客: leetcode刷题记录01——top100题里的7道简单题 leetcode刷题记录02——top100题里的7道简单题 有效的括号 看懂需要用栈了,但是不知道怎么去写,看了题解mark下正确答案。 cla…

求单位球内满足边界条件 u = z³ 的调和函数

问题 6:在区域 {x2y2z2≤1}\{x^{2}y^{2}z^{2}\leq 1\}{x2y2z2≤1} 内找到一个调和函数 uuu,使得在边界 x2y2z21x^{2}y^{2}z^{2}1x2y2z21 上,uuu 等于 gz3gz^{3}gz3。 提示:根据第8.1节,解必须是一个三次调和多项式&…

AAA 服务器与 RADIUS 协议笔记

一、AAA 服务器概述1. 核心定义AAA 是认证(Authentication)、授权(Authorization)和计费(Accounting) 的简称,是网络安全领域中实现访问控制的核心安全管理机制,通过整合三种服务确保…

Vue3源码reactivity响应式篇之数组代理的方法

概览 vue3中对于普通的代理包含对象和数组两类,对于数组的方法是重写了许多方法,具体实现参见packages\reactivity\src\arrayInstrumentations.ts arrayInstrumentations实际上就是一个对象,对象的属性就是数组的方法,属性值就是重…

如何玩转K8s:从入门到实战

一、K8S介绍及部署 1 应用的部署方式演变 部署应用程序的方式上,主要经历了三个阶段: 传统部署:互联网早期,会直接将应用程序部署在物理机上 优点:简单,不需要其它技术的参与 缺点:不能为应用…

综合测验:配置主dns,dhcp,虚拟主机,nfs文件共享等

综合实验(所有设备关闭防火墙和selinux)在appsrv上部署主dns,为example.com提供域名解析 安装bind bind-chroot rootappsrv ~]# yum install bind bind-chroot -y编辑主配置文件,全局配置文件,正向解析文件 [rootappsrv ~]# vim /etc/named.c…

MySQL数据库管理与索引优化全攻略

一、表管理1.建库语法:create database if not exists 数据库名;命名规则:仅可使用数字、字母、下划线、不能纯数字;区分字母大小写;具有唯一性;不可使用MySQL命令或特殊字符。相关命令:show databases; …

基于大模型构建 Java 混淆的方式方法(从入门到精通 · 含开源实践)

1. 目标与威胁模型:你到底想防什么? 把“混淆”当作成本叠加器:让逆向者付出更多时间与技能,而不影响用户体验与可维护性。可用 Collberg 等提出的四指标来权衡:有效性/韧性/隐蔽性/成本(potency/resilience/stealth/cost)。近年的研究也在重审这些评估方法,建议结合可…

RabbitMQ面试精讲 Day 28:Docker与Kubernetes部署实践

【RabbitMQ面试精讲 Day 28】Docker与Kubernetes部署实践 在微服务架构日益普及的今天,消息中间件RabbitMQ已成为解耦系统、异步通信的核心组件。随着云原生技术的成熟,如何在Docker与Kubernetes(K8s)环境中高效、高可用地部署Ra…

神经网络和深度学习介绍

目录 1.深度学习的介绍 2.神经网络的构造 ①神经元结构 ②神经网络组成 ③权重核心性 3.神经网络的本质 4.感知器 单层感知器的局限性: 5.多层感知器 多层感知器的优势: 6.偏置 7.神经网络的设计 8.损失函数 常用的损失函数: 9…

云原生俱乐部-k8s知识点归纳(8)

这一部分主要讲一讲CRD客户资源定义、Gateway API、Priority Class优先类、HPA自动扩缩这四部分内容。还剩下Argo CD的内容了整个k8s,至于operator的话单独有一本书,都是实战内容。CRD客户资源定义先来讲一讲这节内容的几个核心术语,Custom R…

【机器学习】7.随机森林之数学原理

随机森林(Random Forest)的数学原理核心是“决策树基学习器 Bootstrap抽样 特征随机选择” 的集成框架,通过降低单棵决策树的方差、提升模型泛化能力来工作。以下分步骤解析其数学推导与核心逻辑: 一、 基学习器:决策…

大模型微调面试题全解析:从概念到实战

大模型微调面试题全解析&#xff1a;从概念到实战 微调基础概念 本文较长&#xff0c;建议点赞收藏&#xff0c;以免遗失。更多AI大模型开发 学习视频/籽料/面试题 都在这>>Github<< >>gitee<< &#xff08;一&#xff09;什么是微调 微调&#xf…

Linux: network: arp: arp_accept

文章目录 接收 linux 代码 arp协议的处理 接收 arp_accept - BOOLEAN Define behavior for gratuitous ARP frames who’s IP is not already present in the ARP table: 0 - don’t create new entries in the ARP table 1 - create new entries in the ARP table Both repli…

SpringBoot 整合 Langchain4j RAG 技术深度使用解析

目录 一、前言 二、Langchain4j RAG介绍 2.1 什么是LangChain4j 2.2 LangChain4j RAG技术介绍 2.2.1 RAG技术原理 2.2.2 LangChain4j中的RAG实现 2.2.3 LangChain4j RAG技术优势 2.2.4 LangChain4j RAG技术应用场景 三、LangChain4j RAG 技术深度使用 3.1 文档加载与解…

百度深度学习面试:batch_size的选择问题

题目在深度学习中&#xff0c;为什么batch_size设置为1不好&#xff1f;为什么batch_size设为整个数据集的大小也不好&#xff1f;&#xff08;假设服务器显存足够&#xff09;解答这是一个非常核心的深度学习超参数问题。即使显存足够&#xff0c;选择极端的 batch_size 也通常…