zoukankan      html  css  js  c++  java
  • Docker 笔记

    一、Docker for Windows 基础知识

    1. 下载docker for windows。
      docker for windows

    2. 下载安装完后设置"Shared Drives"。

    3. 因为国内访问docker story太慢。需要设置docker加速器: "Daemon"->Registery
      DaoCloud

    4. 安装docker for windows后docker会默认在(Windows10)”Hyper-V“中新建一个”MobyLinuxVM “。

    5. 通过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 常用命令

    1. docker build生成一个镜像。
    2. docker run在一个新的容器中运行镜像。
    3. docker images列出所有镜像。
    4. docker ps列出正在运行的容器。
    5. docker ps -a列出所有容器(包括未运行的)。
    6. docker stop 停止运行一个容器。
    7. docker start启动一个容器。
    8. docker restart重新启动一个容器
    9. docker rm移除一个容器。但不会移除该容器中的镜像。
    10. docker rmi移除镜像。
    11. docker pull拉取一个镜像。
    12. docker inspect查看信息.
    13. 所有命令都可以通过--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:容器启动时执行的命令。

    Dockerfile文件详解

    3、通过Dockerfile文件生成镜像

    docker build . -t islidetools.localserver:1.0

    ".":指Dockerfile文件在当前目录下。

    "-t":指定镜像名称。【注意:名称要小写,大写要报错...】。

    4、运行镜像

    docker run -d -p 8888:80 -v "$pwdpublish:/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自动完成

    posh-docker

    1. 以管理员身份运行PowserShell
    2. 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
    3. To install the posh-docker PowerShell module for auto-completion of Docker commands, type:
      Install-Module posh-docker
    4. After installation to enable autocompletion for the current PowerShell only, type:
      Import-Module posh-docker
    5. 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

    五、资源

    Docker for beginners

    Docker入门教程

    docker image with aspnetcore

    ASP.NET Core 网站在Docker中运行

    作者:liujf
    出处:http://www.cnblogs.com/liujf5566/
    本文版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利~

  • 相关阅读:
    论文笔记:目标检测算法(R-CNN,Fast R-CNN,Faster R-CNN,FPN,YOLOv1-v3)
    论文笔记:IRGAN——A Minimax Game for Unifying Generative and Discriminative Information
    springer论文模板参考文献的顺序问题
    CIFAR和SVHN在各CNN论文中的结果
    论文笔记:CNN经典结构2(WideResNet,FractalNet,DenseNet,ResNeXt,DPN,SENet)
    latex常用符号
    python中的引用传递,可变对象,不可变对象,list注意点
    ImageNet历年冠军和相关CNN模型
    matplotlib 的颜色
    调整matplotlib的图例legend的位置
  • 原文地址:https://www.cnblogs.com/liujf5566/p/7196903.html
Copyright © 2011-2022 走看看