当前位置: 首页 > news >正文

Docker- chapter 1

note 1: docker 利用  volume 进行 presist data。 eg : 

compose.yaml:

volumes:database: //# named db by self

list golbal volumes:

docker volume ls # the volumes on the disk

inpect someone volume:

docker volume inspect multi-container-app_database
# the name of volume (multi-container-app_database)  constitude by the container name(multi-container-app) + the db name (database),and separatored by "_"

result : docker volume inspect  multi-container-app_database

[{"CreatedAt": "2024-02-05T10:20:28Z","Driver": "local","Labels": {"com.docker.compose.project": "multi-container-app","com.docker.compose.version": "2.24.3","com.docker.compose.volume": "database"},"Mountpoint": "/var/lib/docker/volumes/multi-container-app_database/_data","Name": "multi-container-app_database","Options": null,"Scope": "local"}
]

 but you can‘t fint the folder ( docker/volumes/multi-container-app_database/_data ) on your host,

and this the explain by gpt :

/var/lib/docker/volumes/multi-container-app_database/_data 这个路径是在 Docker 的虚拟文件系统中,而不是在你的宿主机的文件系统中。这是因为 Docker 使用了一种名为 UnionFS 的文件系统,它允许 Docker 创建层(layer),并将它们组合成一个单一的视图。

这意味着,即使你在宿主机的文件系统中看不到 /var/lib/docker/volumes/multi-container-app_database/_data 这个路径,你的数据仍然是安全的,它们被存储在 Docker 的虚拟文件系统中。

note 2 : 

  view current containers process status 

docker-compose ps 
# warning : the code run must at the folder  include a yaml/yml file

run a container  :

docker-compose up -d 
# -d mean detach 。that's meaning for the  process run at backend and the command line can continue input 
docker run -d -p 8080:80 --name my_container my_image
  • docker run 是创建并启动容器的命令。
  • -d 参数告诉 Docker 在后台运行容器。
  • -p 8080:80 参数将容器的 80 端口映射到宿主机的 8080 端口。
  • --name my_container 参数为容器指定一个名字 my_container
  • my_image 是你要创建容器的镜像的名字。

note 3 :

explaination  $:docker build -t getting-started . 

  • docker build:这是 Docker 的一个命令,用于从 Dockerfile 构建一个新的 Docker 镜像。
  • -t getting-started-t 参数用于给新构建的镜像指定一个名字(也叫做 tag)。在这个例子中,新构建的镜像的名字是 getting-started
  • .:这个点表示 Dockerfile 位于当前目录。Docker 会在这个目录下查找 Dockerfile,并根据 Dockerfile 的内容来构建镜像。

note 4:

current  running  list containers ( if include stop status  containers)

docker ps  【-a】

 note 5:

# syntax=docker/dockerfile:1FROM node:18-alpine  # Create a new build stage from a base image.
WORKDIR /app    
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000

/app :  WORKDIR /app 这一行设置了后续指令的工作目录为 /app。这意味着后续的指令              (如 RUNCMDENTRYPOINTCOPY 和 ADD)如果指定的是相对路径,那么都会                       在 /app 目  录下执行

COPY :COPY . . 这一行就会将 Dockerfile 所在的目录(. 表示当前目录)下的所有文件                和  目录复制到 Docker 镜像的 /app 目录

CMD : CMD ["node", "src/index.js"] 这一行会在容器启动后在 /app 目录下运                   行 node src/index.js 命令

/app 是 Docker 容器内的一个目录,你可以把它看作是你的应用在 Docker 容器内的“家目录”

note 6:

$ docker run -dp 127.0.0.1:3000:3000 getting-started

The -d flag (short for --detach) runs the container in the background. This means that Docker starts your container and returns you to the terminal prompt. You can verify that a container is running by viewing it in Docker Dashboard under Containers, or by running     docker ps     in the terminal.

The -p flag (short for --publish) creates a port mapping between the host and the container. The -p flag takes a string value in the format of HOST:CONTAINER, where HOST is the address on the host, and CONTAINER is the port on the container. The command publishes the container's port 3000 to 127.0.0.1:3000 (localhost:3000) on the host. Without the port mapping, you wouldn't be able to access the application from the host.

http://www.lryc.cn/news/296476.html

相关文章:

  • 解决IntellIJ Idea内存不足
  • 【网络技术】【Kali Linux】Nmap嗅探(二)多设备扫描
  • 简化版SpringMVC
  • Java密码校验(正则表达式):密码由这四种元素组成(数字、大写字母、小写字母、特殊字符),且必须包含全部四种元素;密码长度大于等于8个字符。
  • 【AMI】2400 环境安装步骤
  • AI:124-基于深度学习的人体遮挡物体重建技术
  • 23种设计模式之单例模式
  • leetCode 30天
  • vue3+vite+ts 配置commit强制码提交规范配置 commitlint
  • PlateUML绘制UML图教程
  • 自然语言处理(NLP)——使用Rasa创建聊天机器人
  • 使用虚拟主机部署多站点
  • Openresty+Lua+Redis实现高性能缓存
  • 基于Vue2用keydown、keyup事件实现长按键盘任意键(或组合键)3秒触发自定义事件(以F1键为例)
  • 【C#】.net core 6.0 设置根目录下某个文件夹可访问,访问创建的图片等资源
  • 报错ValueError: Unknown CUDA arch (8.6) or GPU not supported
  • Golang 并发 Cond条件变量
  • linux 下 chrome 无法在设置里面配置代理的解决方法
  • C#上位机与三菱PLC的通信03--MC协议之A-1E报文解析
  • nodeJS 的 npm 设置国内高速镜像之淘宝镜像的方法
  • Nginx方向代理和负载均衡配置
  • 贪心算法篇
  • springboot/ssm大学生就业服务平台就业招聘宣传管理系统Java系统
  • 上下固定中间自适应布局
  • 3分钟部署完成Docker Registry及可视化管理工具Docker-UI
  • 【npm】修改npm全局安装包的位置路径
  • 数据库切片大对决:ShardingSphere与Mycat技术解析
  • macbook电脑如何永久删除app软件?
  • 安卓——计算器应用(Java)
  • 【笔记】Helm-5 Chart模板指南-8 命名模板