Skip to content

Commit

Permalink
docs: learn docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
okbug committed May 29, 2022
1 parent 084e639 commit da29f46
Show file tree
Hide file tree
Showing 38 changed files with 202 additions and 0 deletions.
18 changes: 18 additions & 0 deletions learn-rust/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@ Rust的主要特点:
- 零成本抽象
- 实用性

> 运行单个文件类似 node app.js
> 创建项目类似 npm init 运行项目类似 npm run script
> cargo就是rust 中的包管理器,类似pip、npm等
运行单个文件
```shell
rustc main.rs
./main
```

创建项目

`cargo new p-name`

运行项目
`cd p-name`

`cargo run`
7 changes: 7 additions & 0 deletions learn-rust/learn/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions learn-rust/learn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "learn"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions learn-rust/learn/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
1 change: 1 addition & 0 deletions learn-rust/learn/target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":8968926148183509743,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.62.0-nightly (69a5d2481 2022-04-27)\nbinary: rustc\ncommit-hash: 69a5d2481e856a5a18885390b8cf6950b9ff8dd3\ncommit-date: 2022-04-27\nhost: aarch64-apple-darwin\nrelease: 1.62.0-nightly\nLLVM version: 14.0.1\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/ajun/.rustup/toolchains/nightly-aarch64-apple-darwin\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"llvm14-builtins-abi\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"v8.1a\"\ntarget_feature=\"v8.2a\"\ntarget_feature=\"v8.3a\"\ntarget_feature=\"v8.4a\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}}
3 changes: 3 additions & 0 deletions learn-rust/learn/target/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7dc4d38f67ba849c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":837929224129467038,"features":"[]","target":10353110337280111280,"profile":11736316127369858332,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/learn-e926fff52fc12343/dep-bin-learn"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions learn-rust/learn/target/debug/deps/learn-e926fff52fc12343.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Users/ajun/Desktop/study/ajunge-docs/learn-rust/learn/target/debug/deps/learn-e926fff52fc12343: src/main.rs

/Users/ajun/Desktop/study/ajunge-docs/learn-rust/learn/target/debug/deps/learn-e926fff52fc12343.d: src/main.rs

src/main.rs:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added learn-rust/learn/target/debug/learn
Binary file not shown.
1 change: 1 addition & 0 deletions learn-rust/learn/target/debug/learn.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/ajun/Desktop/study/ajunge-docs/learn-rust/learn/target/debug/learn: /Users/ajun/Desktop/study/ajunge-docs/learn-rust/learn/src/main.rs
Binary file added learn-rust/main
Binary file not shown.
33 changes: 33 additions & 0 deletions learn-rust/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 所有权问题
*/

// fn main() {
// let a = "hello";
// let b = "hello".to_string();
// let c = a;
// println!("{:?}", a);
// let c = b;
// println!("{:?}", b);
// // ^ value borrowed here after move
// }


/**
* 借用的概念
*/

// fn main() {
// let a = [1, 2, 3];
// let b = &a;
// println!("{:p}", b); // 0x16fd1f14c
// // 可变绑定
// let mut c = vec![1, 2, 3];
// // &mut 是可变引用,要想可变引用,在绑定的时候也必须是可变
// let d = &mut c; // c 和 d 是同一个内存地址
// d.push(4);
// println!("{:?}", d); // [1, 2, 3, 4]
// println!("{:?}", c); // [1, 2, 3, 4]
// let e = &42;
// assert_eq!(42, *e)
// }
120 changes: 120 additions & 0 deletions learnDocker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
## 进入一个正在运行的docker的终端

----

## 运行docker基本流程
docker run -it -p [服务器的端口]:[docker虚拟机的端口] 镜像名称

举例:

`docker run -it -p 80:80 nginx-html`

由于Nginx默认是在80端口,所以docker虚拟机端口选择80
如果要访问 https://服务器ip:3000 访问到文件
那么就需要输入 `docker run -it -p 3000:80 nginx-html`


nginx-html是自己打的镜像

打镜像过程
```shell
mkdir test-single-index
cd test-single-index
vim index.html
vim Dockerfile
docker image build -t nginx-html .
# 这里默认打的使用 Dockerfile这个文件,如果指定文件可以通过 -f 来指定
# docker image build -f node.Dockerfile -t tag-name
```


运行

docker run -it -p 80:80 nginx-html

通过这样的流程 可以打包一个只有index.html的最基础Nginx包

上述Dockerfile内容为

```Dockerfile
# 选择基础镜像
FROM nginx:1.21.0-alpine

# 将上面写的index.html打入到镜像的 Nginx默认目录
# 由于还没有对Nginx进行配置,所以默认进入到这个页面中
ADD index.html /usr/share/nginx/html/index.html
```


### RUN 指令

RUN 可以在镜像中执行shell脚本(包括异步,比如下载、删除等操作)

但是一个RUN指令会产生一层 **Image Layer** (不知道是什么) 会让镜像变得很大
所以在一个RUN指令里面使用 && 和 换行就可以
```Dockerfile
FROM what
RUN echo "Hello" && \
echo "World" && \
echo "!"
```

### 为什么说多次RUN有缓存?
我的理解是 它类似git一样,每次的RUN都需要保存
所以如果有下载文件的话,当次的历史记录也会继续把文件保留
下一次RUN的时候才删除。但是文件依然存在于版本管理的东西内
所以会比较占空间

## Dockerfile中的COPY
COPY和ADD都可以把本地的文件复制到镜像。如果嵌套目录不存在,会自动创建


```Dockerfile
COPY my-file.js /a/b/c/index.js
```


### ADD和COPY的不同点
如果是压缩文件的话,ADD后可以自动解压


### 如何选择

复制一般使用`COPY`,解压使用`ADD`

## WORKDIR
WORKDIR 是指定了当前的工作目录(如果没有就创建)
在指定了工作目录后运行的ADD、COPY等命令,都会默认在工作目录中新建和复制
(相当于是cd到了那个目录再进行操作)


## ARG和ENV

相同点:
在Dockerfile中,同样可以当做变量来使用
```Dockerfile
FROM node:14
ARG NAME=Hello
ENV AGE=18
```

不同点:
ARG灵活,在构建容器的时候可以通过 --build-arg NAME=newName 来改变变量
而不是通过修改Dockerfile
ENV可以打入到虚拟环境中的env里面


## CMD
CMD就是最后一次执行的命令
或者说是 容器启动的时候执行的命令
多个CMD的的话,只会执行最后一个



## 快速清理

快速清理停止的容器
`docker system prune -f`

快速清理没有使用的镜像
`docker image prune -a`

0 comments on commit da29f46

Please sign in to comment.