经过多次踩坑,请教得到一下脚本,如果你有遇到docker部署之后端口不是你指定的端口。应该是docker文件少加了这样一句话 ENV ASPNETCORE_URLS http://+:5004
1.docker文件内容如下
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base ENV ASPNETCORE_URLS http://+:8004 WORKDIR /app EXPOSE 8004 COPY . . ENTRYPOINT ["dotnet", "Apitest.dll"]
在centos终端输入 touch xx.sh
全部脚本如下
#echo ‘>>>删除项目目录‘ #rm -rf /home/admin/my/code/gas #echo ‘>>>创建目录‘ #mkdir /home/admin/my/code/gas echo ‘>>>克隆源代码,并更新代码‘ #git svn clone https:/home/admin/my/code/gas #git svn clone https://www./home/admin/my/code #cd /home/admin/my/code #git svn rebase #echo ‘执行dotnet编译发布‘ #dotnet restore /home/admin/my/code #dotnet build /home/admin/my/code #dotnet publish /home/admin/my/code -o /home/admin/my/code/publish echo ‘>>>获取旧的容器id‘ CID=$(docker ps |grep "dotnetapigas" |awk ‘{print $1}‘) echo $CID echo ‘>>>停止旧的容器‘ if [ "$CID" != "" ];then docker stop $CID echo ‘>>>删除旧的容器‘ docker rm $CID fi echo ‘>>>获取旧的镜像‘ IID=$(docker images |grep "dotnetapi" |awk ‘{print $3}‘) echo $IID if [ "$IID" != "" ];then echo ‘>>>删除旧的镜像‘ docker rmi $IID fi echo ‘构建docker镜像‘ docker build -t dotnetapi /home/admin/my/dockerAutoPublish sleep 10 echo ‘>>>启动新的容器‘ docker run -d -p 5002:5002 --name dotnetapigas dotnetapi
linux下执行是在本目录下执行 ./xx.sh
执行之后 输入 docker ps查看运行中的容器
docker logs 容器名称 可以插入容器启动的日志,容器名称输入前4位就行