Docker笔记

来自于Youtube Net Ninja 的Docker Crash Course。

Docker是一个轻量级(lightweight)的“虚拟机”。它可以让队伍不同的成员在相同的环境下运行应用。

image: 是container的blueprint(蓝图)。像是装修时的脚手架,是建筑的外壳。Image说明了container的配置。Image可以理解为Container的说明书,是用来配置Container的。

container:Docker的运行实例。实际应用在container中运行。

Dockerfile(就是这个名字,不用后缀):配置自己的image时需要的文件。程序配置时会一行一行运行dockerfile中的内容,搭建自己的image。

// Parent image as the base
FROM node:17-alpine

// Set working directory
WORKDIR /app

// copy current terminal files to docker working directory
COPY . .

// RUN means to run the following command during the building time
RUN npm install

// Expose the port
EXPOSE 4000

// CMD means to run the following command during the run time of the container instance.
CMD ["node", "app.js"]

.dockerignore:这里列出不需要被COPY这个命令拷贝到image中的内容(例如node_modules,敏感内容,日志等)。

写法:一行一个。

node_modules

*.md

这句话用来创建一个新的image. -t 代表 -tag,用来命名。最后一个.指的是把当前目录下所有文件放进image。

docker build -t myapp .

这句话用来创建一个新container。 --name 代表给新container命名, -p代表指定port。左边的4000代表本地计算机上的port,右边的代表container expose的port。最后是image的名字。

docker run --name myapp5_c -p 4000:4000 myapp5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值