显示标签为“.net core”的博文。显示所有博文
显示标签为“.net core”的博文。显示所有博文

2016年7月4日星期一

Created an non-root docker image for .NET Core 1.0 so you no worry about yemon or npm's anti-root problem

When use the docker image of .NET Core 1.0 from microsoft/dotnet, have you ever encountered `permission denied '/root/.config/configstore/.....` or `No native-sleep available` or `NuGet Cache` error or some weird problem concerned with file permission about /usr/local?
That's why i build a docker image.

Dockerfile is here. I have pushed to docker hub as osexp2000/dnetcore_docker_image.

dnetcore_docker_image

An non-root docker image for .NET Core development( having created normal user id with sudoable, installed nodejs, yeoman, aspnet generator...), you won't worry about yeomen's anti-root problem and some other permission problem about /usr/local.
Usage:
To just use the docker image:
docker run -it osexp2000/dnetcore_docker_image
You will get a bash running with normal user id named dev_user which can sudo without password.
Then you can run aspnet generator:
yo aspnet
And also installed some other utilities vim,lsofnetstat.
A screenshot:
$ docker run -it osexp2000/dnetcore_docker_image
dev_user@640be8c28a81:~$ id
uid=1000(dev_user) gid=1000(dev_user) groups=1000(dev_user),27(sudo)
dev_user@640be8c28a81:~$ yo aspnet
? ==========================================================================
We're constantly looking for ways to make yo better!
May we anonymously report usage statistics to improve the tool over time?
More info: https://github.com/yeoman/insight & http://yeoman.io
========================================================================== Yes

     _-----_     ╭──────────────────────────╮
    |       |    │      Welcome to the      │
    |--(o)--|    │  marvellous ASP.NET Core │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? What type of application do you want to create? (Use arrow keys)
❯ Empty Web Application
  Console Application
  Web Application
  Web Application Basic [without Membership and Authorization]
  Web API Application
  Class Library
  Unit test project (xUnit.net)

To build it yourself:
docker build -t IMAGE_NAME_HERE --rm https://raw.githubusercontent.com/sjitech/dnetcore_docker_image/master/Dockerfile
or download the Dockerfile then run:
docker build -t IMAGE_NAME_HERE --rm - < Dockerfile

.NET Core 1.0学习(3)-做了个靠谱点的docker image)

本来想进一步做aspnet的练习,结果在docker里练到"Building Projects with Yeoman"的地方就碰到了yeomon那些鸟人故意搞的"去root化"问题,用root执行它就唧唧歪歪爆无聊的错,一个个硬chmod是可以,但是不爽,干脆就自己做个Dockerfile生成一个能够在里面开发的docker image吧,全当练习Docker Image制作了。

碰到的错误就是那permission denied '/root/.config/configstore/insight-yo.yml'呀,Attempt To Unlock * Which Hasn't Been LockedNuGet cache之类的错误。前者是yemon的,后者是nodejs安装的不够新(apt-get install nodejs的是0.10级别的版本,谁想的到啊)
做好的docker image叫osexp2000/dnetcore_docker_image (或者osexp2000/dnetcore,更新快些)。
docker run -it osexp2000/dnetcore_docker_image
进去之后就是bash,以dev_user用户运行在/home/dev_user,这个用户能够sudo(无需密码)。
进去就可以顺利的运行aspnet模版生成工具yeomen了。
yo aspnet
里面什么npm和yeomen之类的东西都准备好了,甚至基本的vim,lsofnetstat之类的都准备好了,不然真不方便查看环境。
运行的样子是这样的:
$ docker run -it osexp2000/dnetcore_docker_image
dev_user@640be8c28a81:~$ id
uid=1000(dev_user) gid=1000(dev_user) groups=1000(dev_user),27(sudo)
dev_user@640be8c28a81:~$ yo aspnet
? ==========================================================================
We're constantly looking for ways to make yo better! 
May we anonymously report usage statistics to improve the tool over time? 
More info: https://github.com/yeoman/insight & http://yeoman.io
========================================================================== Yes

     _-----_     ╭──────────────────────────╮
    |       |    │      Welcome to the      │
    |--(o)--|    │  marvellous ASP.NET Core │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? What type of application do you want to create? (Use arrow keys)
❯ Empty Web Application 
  Console Application 
  Web Application 
  Web Application Basic [without Membership and Authorization] 
  Web API Application 
  Class Library 
  Unit test project (xUnit.net)

Dockerfile放在这儿了。很少,干脆贴下来。
FROM microsoft/dotnet

RUN apt-get update

#install nodejs 6.x
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs


#install aspnet generator
RUN npm install -g yo bower grunt-cli gulp
RUN npm install -g generator-aspnet




#this must be installed
RUN apt-get install -y sudo


#these are optional utilities
RUN apt-get install -y vim
RUN apt-get install -y bash-completion
RUN apt-get install -y lsof
RUN apt-get install -y net-tools
RUN apt-get install -y man
RUN apt-get install -y less
RUN apt-get install -y netcat



#add developer user
RUN adduser --disabled-password --gecos "Developer" dev_user
RUN adduser dev_user sudo
RUN echo "dev_user ALL=(ALL:ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)


#optional aliases
RUN echo 'alias ll="ls -lFa"' >> ~/.bashrc
RUN echo 'alias ll="ls -lFa"' >> /home/dev_user/.bashrc

#this is also important so yomen will not complains
RUN chown -R root:sudo /usr/local

RUN rm -f /core
RUN rm -fr /tmp/NuGetScratch

USER dev_user
WORKDIR /home/dev_user
可以自己存起来build成docker image
docker build -t IMAGE_NAME_HERE --rm - < Dockerfile

下次再沿着Your First ASP.NET Core Application on a Mac Using Visual Studio Code — ASP.NET documentation继续学。不过我想看看如何通过Mac OS X里的Visual Studio Code来直接把代码发布到docker里。

.NET Core 1.0学习(2)

做了个简单的aspnet练习,再总结一下上次的经验

随便照着[Getting Started — ASP.NET documentation做了一下练习,实在无趣。就是改个project.json再写个hello world。
什么Code Behind(aspx, aspx.cs),事件代码的, 都没看到。(就看Visual Studio Code的本事了,不然就没有微软特色了)
贴个代码结束 (用的不是和IIS或者IIS Express配套的那个ASP.NET,想用也没有。而是Kestrel,名字是一种鸟,鸟Server?)。
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;

namespace aspnetcoreapp
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.Run(context =>
            {
                return context.Response.WriteAsync("Hello from ASP.NET Core!");
            });
        }
    }
}
再回想起上次练习.NET Core 1.0学习(1),发现了几点不同寻常的地方:
  1. .NET Core的东西好精简。加起来才180个文件左右,109M左右。都放在/usr/share/dotnet下。 (毋庸置疑,里面也包含了ASP.NET Core的东西,我做了简单的aspnet试了OK。$HOME/.nuget下的东西和dotnet下的东西雷同很多。)
    反正比起Windows上那一坨坨的实在清爽太多。
    可是为啥能够少这么多呢? (1)大量的Windows GUI相关的东西去掉了,我没有看到任何和form相关的东西。更不要提那劳什子WPF,Silverlight了。 (2)一个是Windows上的GAC去掉了,估计连功能都没做。 (3)ASP.NET的东西似乎极少,都没看到以前的System.Web.Dll。
  2. IIS不见踪影 也没看见什么Express的字样。 做最初的aspnet的例子时发现是用Microsoft.AspNetCore.Server.Kestrel来做Server的,靠谱吗?不知道,看了github里的介绍aspnet/KestrelHttpServer,不冷不热吧,都没怎么看见宣传,说好的IIS Express呢?
  3. 看见了libuv的身影。 这东西才是NodeJS的半壁江山,异步事件驱动高效而且跨平台的lib。上面提到的KestrelHttpServer就是用它做的,难怪这么小。
    突然想起来,以前IIS特意把HTTP的一些处理放倒内河层做(http.sys)以便快速的处理request/response, IIS的速度也的确挺强悍,可是现在不用这个体制会怎么样?如果能够很好,那么为什么还要做的那么啰嗦。看来微软也被libuv征服了,这是应该的。
  4. 看见了VB的身影 /root/.nuget/packages/Microsoft.VisualBasic/10.0.1/ref/netcore50/Microsoft.VisualBasic.dll看来也许会支持,其实也不是什么大事儿,因为画面是甭指望的了,有没有他谁还在乎。

微软扔掉了UI,赤膊到Linux上拼搏,优势大减啊。.NET Runtime本身的速度和Java VM的相比自然不能快到哪里去,否则JVM必然会超过。 这个.NET Core搞好了,大家当然都愉快,就看微软给不给力了,可别来个太粗暴的一刀切什么的。