1.docker环境

[root@wikifx2 ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              0901fa9da894        10 days ago         132MB
nginx               latest              0901fa9da894        10 days ago         132MB
alpine              latest              a24bb4013296        7 weeks ago         5.57MB
centos              7                   b5b4d78bc90c        2 months ago        203MB
[root@wikifx2 ~]# docker run -it a24bb4013296
/ # 
/ # [root@wikifx2 ~]# ctrl + p && ctrl + q #临时退出
[root@wikifx2 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
173daf6285ba        a24bb4013296        "/bin/sh"           9 seconds ago       Up 8 seconds                            tender_ramanujan
[root@wikifx2 ~]#  docker attach 173daf6285ba #再次进入

2.查看源:

/ # cat /etc/apk/repositories 
http://dl-cdn.alpinelinux.org/alpine/v3.12/main
http://dl-cdn.alpinelinux.org/alpine/v3.12/community

3.修改源:

/ # sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories 
/ # cat /etc/apk/repositories 
http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.12/main
http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.12/community

4.构建缓存:

apk update

5.安装依赖:

/ # apk add libstdc++ icu libintl

6.安装 .NET Core Runtime

/ # wget https://download.visualstudio.microsoft.com/download/pr/34014520-3b9c-43a0-bc79-a5323655e235/fda26e0a67b9cf21ad648ff0c6259668/aspnet
core-runtime-3.1.6-linux-musl-x64.tar.gz

/ # mkdir -p /app/dotnet
/ # tar -xf aspnetcore-runtime-3.1.6-linux-musl-x64.tar.gz -C /app/dotnet/

7.编写启动脚本:

cd /wwwroot/ && /app/dotnet/dotnet WebApplication5.dll --urls http://0.0.0.0:8000
tail -f /etc/hosts

docker commit a35e206825ed wikifx_dotnet:v4   #存储为镜像
docker image save  7a4ab67f3701 > wikifx_dotnetv4.tar.gz  #导出

宿主机dotnet写的hello word项目:

[root@wikifx2 ~]# tree /wwwroot/
/wwwroot/
├── a624669980.tar.gz
├── appsettings.Development.json
├── appsettings.json
├── WebApplication5
├── WebApplication5.deps.json
├── WebApplication5.dll
├── WebApplication5.pdb
├── WebApplication5.runtimeconfig.json
└── web.config

0 directories, 9 files

8.启动:

docker run -it -d -p 80:8000 -v /wwwroot:/wwwroot 7a4ab67f3701 /bin/sh /etc/init.sh
test


本博客所有文章除特别声明外,均采用 CC 署名-非商业性使用-禁止演绎 4.0 国际 。转载请注明出处!

Docker-安装&基础管理 下一篇