Docker 笔记
Docker
1.构建netcore5.0 的jenkins镜像
FROM jenkins/jenkins
# Switch to root to install .NET Core SDK
USER root
# Show distro information!
RUN uname -a && cat /etc/*release
# Based on instructiions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install dependency for .NET Core 3
RUN apt-get update
RUN apt-get install -y curl libunwind8 gettext apt-transport-https
# Based on instructions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install microsoft.qpg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
RUN mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list'
# Install the .NET Core framework
RUN apt-get update
RUN apt-get install -y dotnet-sdk-5.0
# Switch back to the jenkins user.
USER jenkins
//镜像已经构建好了
docker run -u root -d -p 3001:8080 --name jenkins5 \
-v /etc/localtime:/etc/localtime \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/dockerVolumes2/jenkins_home5:/var/jenkins_home \
myjenkins:1.0
//发布代码,重新生成镜像,运行
dotnet restore
dotnet build
cd WebApplication1
dotnet publish
cd bin/Debug/net5.0/publish/
docker stop testptoject1
docker rm testptoject1
docker rmi myjenkins:1.0
docker build -f Dockerfile -t testproject:1.0 .
docker run --name=testptoject1 -d -v /etc/localtime:/etc/localtime -it -p 4006:80 testproject:1.0
命令
-
删除所有容器 docker rm ```docker ps -a -q`` `
-
删除所有镜像 docker rmi ```docker images -q`` `
https://mp.weixin.qq.com/s/ngUfM27drd3fApC2PlJkOQ
1.老张的哲学,docker安装netcore(视频:https://www.bilibili.com/video/BV1vC4y1p7Za?p=26)
//更新系统 (新购买的linux系统)
sudo yum update
#Step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#Step 3: 缓存并安装Docker-CE(可选)
sudo yum makecache fast
sudo yum -y install docker-ce
#Step 4: 开启Docker服务
sudo service docker start
#Step 5: 设置Docker开机自启动
systemctl enable docker
#Step 6: 启动Docker
systemctl start docker
#Step 7: 查看版本
docker --version
#你可以使用docker run hello-world 做下测试
docker search jenkins #(查看官方镜像中的jenkins)
#其中第一个和第二个其实都是官方的,但是第一个已经不维护了,我们一般都是使用的第二个。
#但是这样是有问题的,因为jenkins的docker版本本身没有dotnetcore的环境,所以我们需要先自己动手制作下包含dotnet环境的jenkins的Docker的Container
#创建一个Dockerfile文件
FROM jenkins/jenkins
# Switch to root to install .NET Core SDK
USER root
# Show distro information!
RUN uname -a && cat /etc/*release
# Based on instructiions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install dependency for .NET Core 3
RUN apt-get update
RUN apt-get install -y curl libunwind8 gettext apt-transport-https
# Based on instructions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current
# Install microsoft.qpg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
RUN mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list'
# Install the .NET Core framework
RUN apt-get update
RUN apt-get install -y dotnet-sdk-3.1
# Switch back to the jenkins user.
USER jenkins
# 1. 编辑Dockerfile (详见Dockerfile示例)
# 2. 构建镜像(当前路径),最后的.是当前路径
docker build -t my-docker-jenk .
#(指定文件生成镜像)docker build -f Dockerfile5 -t mydockerjenkins:5.0 .
//创建工作目录
mkdir /home/jenkins_home
//赋予权限
chown -R 1000 /home/jenkins_home
#运行jenkins docker run -d --name jenkins_01 -p 80:8080 -v /home/jenkins_01:/home/jenkins_home mydockerjenkins:5.0 (有一定问题没解决,密码没有挂载出来)
#运行docker run -u root -d -p 3001:8080 --name jenkins5 \
-v /etc/localtime:/etc/localtime \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/dockerVolumes2/jenkins_home5:/var/jenkins_home \
mydockerjenkins:5.0
#/home/dockerVolumes2/jenkins_home5/secrets/查看密码
#Jenkins默认的开放容器端口是8080和50000,但是你可以自定义宿主机的监听端口,比如我 这里就直接80端口了
#浏览地址安装jenkins 地址ip一定是ifcongfig查询的虚拟机ip(坑)
第一次构建项目
dotnet restore
dotnet build
cd WebApplication1
dotnet publish
cd bin/Debug/net5.0/publish/
docker build -f Dockerfile -t testproject:1.0 .
docker run --name=testptoject1 -d -v /etc/localtime:/etc/localtime -it -p 3002:80 testproject:1.0
第二次构建项目
dotnet restore
dotnet build
cd WebApplication1
dotnet publish
cd bin/Debug/net5.0/publish/
docker stop testptoject1
docker rm testptoject1
docker rmi `docker images testproject -aq`
docker build -f Dockerfile -t testproject:1.0 .
docker run --name=testptoject1 -d -v /etc/localtime:/etc/localtime -it -p 3002:80 testproject:1.0
浙公网安备 33010602011771号