Docker安装
windows需安装桌面版。
Windows
WslRegisterDistribution failed with error: 0x80370114
1, Open “Windows Security”
2, Open “App & Browser control”
3, Click “Exploit protection settings” at the bottom
4, Switch to “Program settings” tab
5, Locate “C:\WINDOWS\System32\vmcompute.exe” in the list and expand it
6, Click “Edit”
7, Scroll down to “Code flow guard (CFG)” and uncheck “Override system settings”
8, Start vmcompute from powershell “net start vmcompute”
After doing the above Hyper-V Quick Create launched correctly.
Then go back and command
wsl --set-default-version 2 Install linux, success!
https://softwaretested.com/windows/wslregisterdistribution-failed-with-error-0x80370114/
Docker加速(配置国内镜像源)
镜像源路径,应在网上搜索最新的替换。
通过 Docker-Desktop 配置
添加:
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com"
]
通过 daemon.json 配置
windows 下路径:C:\Users\Administrator.docker\ 创建或修改 /etc/docker/daemon.json 文件
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
- 重启docker
docker info
查看
Windows Docker 配置国内镜像源的两种方法_docker desktop 配置多个镜像源默认使用哪个镜像源-优快云 博客
常用指令
# 启动docker镜像
docker run -it neo4j:latest
# 查看
docker images
docker ps
# 查看运行状态的容器
docker ps -a
# 查看终止状态的容器
docker ps -n 5
# 终止运行中的容器
docker stop containerID
# 删除镜像
docker ps # 先查看
docker stop containerID # 停止容器
docker rm containerID # 删除容器
docker rmi imageId # 删除镜像
# 启动
docker start
# 重新载入
docker reload
docker logs
# 容器与主机之间的数据拷贝
sudo docker cp da04dd5bf4c0:/home/matlab/Documents /home/user/ww/matlab
# 重启docker
sudo service docker restart
# 或
sudo systemctl daemon-reload
sudo systemctl restart docker
# 查看容器内文件目录
docker exec containerID ls [\tmp]
# 查看容器挂载目录
docker inspect containerID | grep Mounts -A 20
Docker使用
生成requirements.txt
pip freeze > requirements.txt
.dockerignore
Docker在读取应用上下文中的Dockerfile文件进行镜像构建之前,都会先查看当前应用上下文中是否包含一个名为.dockerignore的文件。
- 如果该文件存在,则Docker会先将.dockerignore文件中声明的文件或目录进行排除,然后再读取Dockerfile进行镜像构建。
Dockerfile
FROM python:3.8
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
COPY . /hello
WORKDIR /hello
EXPOSE 3000
CMD ["python", "hello.py"]
- EXPOST :监听端口
- WORKDIR :设置容器的工作目录,每一个 RUN 命令都是新建的一层
构建镜像
build创建本地新镜像
docker build -t hello:v1 .
- hello:v(镜像名称:镜像标签)
.
:上下文路径(把我们本机的指定目录下的文件一起打包提供给 docker 引擎使用)
查看所有image
docker images
发布到网上
docker login gitlab.com
docker tag hello:v1 username/hello-docker
docker push username/hello-docker
拉取并运行镜像
docker pull
docker run -t -i -p 1872:8080 rainbow0106/hidden_event:latest # 将容器的 8080 端口映射到主机的 1872 端口
镜像导入与导出
导出
docker save -o hello.tar hello:v1
# docker save -o [tar包名] [仓库名]:[标签] # 保存镜像为本地文件
ll -h
导入
docker load --input 文件
docker load < 文件名
与github关联
- 在Github上面创建一个项目并把 Dockerfile 当到项目的根目录中
- 绑定仓库服务
- 在Docker Hub上创建一个Auto build,关联Github上的repository
- https://shanhy.blog.youkuaiyun.com/article/details/89148877
常见问题
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting “xxx/elasticsearch.yml” to rootfs at “/usr/share/elasticsearch/config/elasticsearch.yml” caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
- xxx/elasticsearch.yml为一个目录,或文件不存在(路径错误)。