重新认识2021-01-14
1. Windows 安装和配置 WSL - 简书 (jianshu.com)
Windows 安装和配置 WSL
什么是 WSL
Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层。 它是由微软与Canonical公司合作开发,目标是使纯正的Ubuntu 14.04 "Trusty Tahr"映像能下载和解压到用户的本地计算机,并且映像内的工具和实用工具能在此子系统上原生运行。
WSL:适用于 Linux 的 Windows 子系统。
- 什么是适用于 Linux 的 Windows 子系统?
适用于 Linux 的 Windows 子系统可让开发人员按原样运行 GNU/Linux 环境 - 包括大多数命令行工具、实用工具和应用程序 - 且不会产生虚拟机开销。
- 什么是 WSL2?
WSL2 是适用于 Linux 的 Windows 子系统体系结构的一个新版本,它支持适用于 Linux 的 Windows 子系统在 Windows 上运行 ELF64 Linux 二进制文件。 它的主要目标是提高文件系统性能,以及添加完全的系统调用兼容性。
把系统升到了Windows 10 2004,然后在安装Docker Desktop(2.3.0.3版本)时发现跟以前不太一样了。现在Docker Desktop默认使用WSL 2来运行,而不是以前的Hyper-V。
安装docker之后, 启用了新版win10的wls2,docker的运行数据都在wls发布版中,文件位置由wsl管理
查看是不是WSL2,
wsl -l -v
你可以在运行(win+R)或资源管理器的路径里直接输入\wsl$进入Ubuntu的目录
初次认识2020-10-01
微软: 适用于 Linux 的 Windows 子系统安装指南 (Windows 10)
docs.microsoft.com/zh-cn/windo…
Docker是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源
Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
Docker的三个概念:
-
镜像(Image):A Docker image is a private file system just for your container. It provides all the files and code your container needs. 镜像是一个包含有文件系统的面向Docker引擎的只读模板,容器的全部所需都来源于镜像。例如一个Ubuntu镜像就是一个包含Ubuntu操作系统环境的模板,同理在该镜像上装上Apache软件,就可以称为Apache镜像
-
容器(Container):容器是镜像创建的应用实例。注意:镜像本身是只读的,容器从镜像启动时,Docker在镜像的上层创建一个可写层,镜像本身不变,类似我们操作虚拟机不会改变虚拟机的镜像。容器可以创建、启动、停止、删除
Since the image contains the container's filesystem, it must contain everything needed to run an application - all dependencies, configuration, scripts, binaries, etc. The image also contains other configuration for the container, such as environment variables, a default command to run, and other metadata.
- 仓库(Repository):类似于git仓库,是Docker用来集中存放镜像文件的地方。而仓库Repository又存放在注册服务器registry中【官方注册服务器(hub.docker.com】)。
整个的关系链是registry -> Repository -> image
1.安装docker www.docker.com/products/do…
2.容器化2步走,很简单,首先来个镜像,然后run,一run就是创了个容器
a. 镜像哪里来
从官方注册服务器registry的仓库Repository中pull下来
使用命令 docker search image_name[:version_tag] 查找仓库中有没有要的镜像
使用命令 docker pull image_name[:version_tag] pull下来
docker images // 查看现有镜像
docker ps -XXX // 查看容器状态
b. 自建镜像
可以将容器导出为镜像。例如一个容器运行centos系统镜像,原镜像没有golang,我装上golang之后,通过commit命令将带有git的centos系统导出为新的镜像
docker commit -a "author_name" -m "message" source_containerid image_name[:version_tag]
同时,也可以利用Dockerfile + docker build 命令创建镜像(重要)。A Dockerfile is simply a text-based script of instructions that is used to create a container image.
Dockerfile文件模板
FROM primary_image // 表示 start from 基础镜像primary_image。如果primary_image在本地已经存在,则直接使用本地的镜像;否则会从官方repo里面pull下来
ENV key=value // 设置新镜像的环境变量
ARG key=value // 设置build镜像过程中的临时变量
COPY source des // 从本地上下文目录中复制文件或者目录到容器里指定路径,容器内的指定路径不用事先建好,会自动创建
RUN shell_command // 建镜像的过程中执行shell_command
CMD command // 镜像建好后,装入容器运行时执行command. 如果 Dockerfile 中如果存在多个 CMD 指令,仅最后一个生效
3. 镜像run起来,容器new起来
当镜像通过run启动后,就载入到一个动态的container(容器)中运行
常用run命令为
$ docker run -d [-p outer_port:container_port] -it image_name[:version_tag] /bin/bash
// 参数说明
-it: -i和-t的组合,interactive flag, TTY flag (gives you a terminal),开启交互模式
-p outer_port:container_port: 宿主机端口到容器端口的映射
-d: - run the container in detached mode (in the background),返回容器ID。因此一般不和-it连用
run起来后,使用docker ps -a查看所有容器(status包括running and stop)
//启动或停止容器
docker start/stop containerid
//后台运行的容器转交互模式
docker exec -it containerid /bin/bash
//删除容器
docker rm containerid
//删除镜像
docker rmi imageid
docker更换镜像源
添加镜像源文件
{"registry-mirrors":
["https://pee6w651.mirror.aliyuncs.com"]
}
这里注意提醒一下,如果你更换源之后马上拉取镜像,可能该配置没有生效,所以依然很慢,所以需要重启以下docker后即可解决问题!
国内可用的镜像源
//官方中国区
https://registry.docker-cn.com
//网易
http://hub-mirror.c.163.com
//阿里云
https://pee6w651.mirror.aliyuncs.com
//参考:
https://segmentfault.com/a/1190000022574084
//参考:
https://www.jianshu.com/p/e3eddc7faa4e
// hub.docker.com
// 网易蜂巢 hub
// daoCloud hub.daoCloud.io