Net Core Docker 容器部署,修改,保存
运行镜像
[root@localhost opt]# docker run -itd -p 80:80 microsoft/dotnet:latest
查看运行的docker
[root@localhost opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f3aff5ca8aa3 microsoft/dotnet:latest "bash" 21 seconds ago Up 17 seconds 0.0.0.0:80->80/tcp upbeat_kapitsa
拷贝代码到容器的/opt目录,然后进入之容品
[root@localhost dockernet]# docker cp app f3aff5ca8aa3:/opt [root@localhost dockernet]# [root@localhost dockernet]# [root@localhost dockernet]# docker exec -it f3aff5ca8aa3 /bin/bash root@f3aff5ca8aa3:/# cd /opt root@f3aff5ca8aa3:/opt# ls app
到程序目录后运行
root@f3aff5ca8aa3:/opt/app# dotnet PhoneCard.dll
成功运行
把修改的容器保存为镜像
[root@localhost dockernet]# docker commit f3aff5ca8aa3 mynetweb sha256:ebd813a36273ccd6dab11ffe4eab9ff3da01b4848c97b3ac9eb7ee170b001a72 [root@localhost dockernet]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mynetweb latest ebd813a36273 7 seconds ago 1.76GB
进入容器启动,可以看到两个正在运行的容器
[root@localhost dockernet]# docker run -itd -p 8080:80 mynetweb
[root@localhost dockernet]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 685a6c44c03b mynetweb "bash" 7 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp elated_kilby f3aff5ca8aa3 microsoft/dotnet:latest "bash" 22 minutes ago Up 22 minutes 0.0.0.0:80->80/tcp upbeat_kapitsa [root@localhost dockernet]# docker exec -it 685a6c44c03b /bin/bash root@685a6c44c03b:/# cd /opt root@685a6c44c03b:/opt# ls app root@685a6c44c03b:/opt# cd app
启动后成功运行
root@685a6c44c03b:/opt/app# dotnet PhoneCard.dll
保存容器为文件
[root@localhost dockernet]# docker export 685a6c44c03b > docker1.tar
[root@localhost dockernet]# ls
app docker1.tar Dockerfile
导入容器
docker import - docker1 < docker1.tar