Docker 笔记
一、Docker for Windows 基础知识
-
下载docker for windows。
docker for windows -
下载安装完后设置"Shared Drives"。
-
因为国内访问docker story太慢。需要设置docker加速器: "Daemon"->Registery
DaoCloud -
安装docker for windows后docker会默认在(Windows10)”Hyper-V“中新建一个”MobyLinuxVM “。
-
通过
docker version
查看当前版本信息。
Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:30:30 2017
OS/Arch: windows/amd64
Server:
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:51:55 2017
OS/Arch: linux/amd64
Experimental: true
二、Docker 常用命令
docker build
生成一个镜像。docker run
在一个新的容器中运行镜像。docker images
列出所有镜像。docker ps
列出正在运行的容器。docker ps -a
列出所有容器(包括未运行的)。docker stop
停止运行一个容器。docker start
启动一个容器。docker restart
重新启动一个容器docker rm
移除一个容器。但不会移除该容器中的镜像。docker rmi
移除镜像。docker pull
拉取一个镜像。docker inspect
查看信息.- 所有命令都可以通过
--help
查看具体用法。
三、iSlideTools.Localserver 部署到docker方法
1、发布项目到当前工程目录下的"publish"文件夹。【注意:把data.db数据库从输出目录拷贝过来】。
2、 在当前工程目录下新建Dockerfile文件。
FROM microsoft/aspnetcore:1.1
WORKDIR /app
EXPOSE 80
COPY publish .
ENTRYPOINT ["dotnet", "iSlideTools.LocalServer.dll"]
FROM
:告诉docker基于microsoft/aspnetcore:1.1
构建你的镜像。
WORKDIR
:设置/app为工作目录。
EXPOSE
:暴露80端口。
COPY
:从"publish"拷贝文件或目录到容器中的目录。
ENTRYPOINT
:容器启动时执行的命令。
3、通过Dockerfile文件生成镜像
docker build . -t islidetools.localserver:1.0
".":指Dockerfile文件在当前目录下。
"-t":指定镜像名称。【注意:名称要小写,大写要报错...】。
4、运行镜像
docker run -d -p 8888:80 -v "$pwd\publish:/app" --name islidetoolslocalserver islidetools.localserver:1.0
"-d":容器在后台运行。
"-p":映射端口。
"-v":挂载目录。将当前目录下的"publish"目录挂载到容器的"app"目录。
"--name":指定容器名称。
最后是镜像名称。":"后面是tag。如果不指定默认是"latest"。
检查是否挂载上目录执行:docker inspect 容器名称
。查看"Mounts"节点是否有数据。
我当前挂载的目录如下:
"Mounts": [
{
"Type": "bind",
"Source": "/C/Users/liujf/Documents/Dev/Repos/islide-tools-public/src/iSlideTools.LocalServer/iSlideTools.LocalServer/publish",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
docker ps
:查看当前正在运行的容器。
5、维护
当修改bug后,重新发布网站到"publish"文件夹。执行docker restart 容器名称
就能看见更新后的内容。
四、配置PowerShell
使用Tab
自动完成
- 以管理员身份运行PowserShell
- Set the script execution policy to allow downloaded scripts signed by trusted publishers to run on your computer. To do so, type this at the PowerShell prompt.
Set-ExecutionPolicy RemoteSigned
- To install the posh-docker PowerShell module for auto-completion of Docker commands, type:
Install-Module posh-docker
- After installation to enable autocompletion for the current PowerShell only, type:
Import-Module posh-docker
- To make tab completion persistent across all PowerShell sessions, add the command to a $PROFILE by typing these commands at the PowerShell prompt.
if (-Not (Test-Path $PROFILE)) {
New-Item $PROFILE –Type File –Force
}
Add-Content $PROFILE "`nImport-Module posh-docker"
This creates a $PROFILE if one does not already exist, and adds this line into the file:
Import-Module posh-docker
To check that the file was properly created, or simply edit it manually, type this in PowerShell:
Notepad $PROFILE
五、资源
作者:liujf
出处:http://www.cnblogs.com/liujf5566/
本文版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利~