Docker- chapter 1

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

compose.yaml:

javascript 复制代码
volumes:
  database: //# named db by self

list golbal volumes:

cpp 复制代码
docker volume ls # the volumes on the disk

inpect someone volume:

cpp 复制代码
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

cpp 复制代码
[
    {
        "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

cpp 复制代码
docker-compose ps 
# warning : the code run must at the folder  include a yaml/yml file

run a container :

cpp 复制代码
docker-compose up -d 
# -d mean detach 。that's meaning for the  process run at backend and the command line can continue input 

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)

cpp 复制代码
docker ps  【-a】

note 5:

cpp 复制代码
# syntax=docker/dockerfile:1

FROM 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。这意味着后续的指令 (如 RUN, CMD, ENTRYPOINT, COPYADD)如果指定的是相对路径,那么都会 在 /app 目 录下执行

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

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

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

note 6:

cpp 复制代码
$ 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.

相关推荐
一条懒鱼6664 分钟前
K8S-Ingress资源对象
云原生·容器·kubernetes
风掣长空22 分钟前
Google Test (gtest) 新手完全指南:从入门到精通
运维·服务器·网络
luback31 分钟前
前端对Docker简单了解
运维·docker·容器
0思必得040 分钟前
[Web自动化] 开发者工具应用(Application)面板
运维·前端·python·自动化·web自动化·开发者工具
帷幄庸者1 小时前
记一次Kubernetes“僵尸”挖矿病毒的排查与歼灭全录
云原生·容器·kubernetes
LEEE@FPGA1 小时前
ZYNQ MPSOC linux hello world
linux·运维·服务器
漏洞文库-Web安全1 小时前
Linux逆向学习记录
linux·运维·学习·安全·web安全·网络安全·逆向
无奈笑天下1 小时前
【银河麒麟高级服务器部署本地yum源】
linux·运维·服务器·经验分享
wanhengidc2 小时前
云手机 数字生活中新的可能
运维·服务器·科技·安全·智能手机·生活
Likeadust2 小时前
视频直播点播平台EasyDSS助力企业打造全场景数字化宣传体系
运维·人工智能·音视频