I have been using the.net core image of CentOS7 for a long time, and recently I found out that 8 has been released, so I want to update the environment. After all, many people have reported that there are some bugs in 7, so the problem that can be solved by updating the system is not a problem, because I did not write the system, haha, I can not find the bug.

Write your own Dockerfile

The format of Dockerfile is very simple, costs almost nothing to learn, and is extremely easy to build, so let’s start with this file.

#Upgrade to 8, simple, direct copy of centos7 image file
FROM centos:8

#Create your own environment variables. Add the normal environment variables first to avoid using them empty
#For example, DOTNET_RUNNING_IN_CONTAINER can be used to check whether the program is running in a containerENV DOTNET_CORE_VERSION= 3.1dotnet_framework = netcoreApp3.1 # Microsoft's images set this to enable detecting when an  app is running in a container. DOTNET_RUNNING_IN_CONTAINER=true \ TZ=Asia/Shanghai#Added time zone for Shanghai
#CentOS 8 Add Chinese font encoding and set the local encoding to Chinese UTF-8
RUN yum install -y langpacks-zh_CN
RUN export LANG=zh_CN.UTF-8
RUN echo -e "export LANG=zh_CN.UTF-8" > /etc/locale.conf
RUN echo -e "export LANG=zh_CN.UTF-8" > /etc/profile
RUN source /etc/profile
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8

#Copy the installation of the official website
# Install .NET CoreRUN dotnet_version=3.1.10 \ && curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-linux-x64.tar.gz \ # https://dotnetcli.blob.core.windows.net/dotnet/Runtime/3.1.10/dotnet-runtime-3.1.10-linux-x64.tar.gz # download missile in china ======== && dotnet_sha512='7ff09caf2cdff0ae1c75d0ac731267ffa624025137b079134eb9fda15e1ca386af8422ddd3e93ba084853006e7d58bc04bdf232ad 3762580e94658ce3dc8f984' \ && echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \ && mkdir -p /usr/share/dotnet \ && tar -ozxf dotnet.tar.gz -C /usr/share/dotnet \ && rm dotnet.tar.gz \ && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
#Install gdiplus library
# install libgdiplus
#Install THE ICU library't find a valid ICU package installed on the system. 
#   Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
RUN yum install  -y epel-release && \
    yum install -y libgdiplus-devel && \   
    yum install -y icu && \  
    yum clean all -y && \
    rm -rf /var/cache/yum/*

#Plus China time zone
# chinese timezone
RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone
Copy the code

Slow download

Microsoft’s official download path is too slow, both addresses are slow. I downloaded it myself and changed it to a local build

#Copy dotnet from local to containerCOPY dotnet runtime - 3.1.10 - Linux - x64. Tar. Gz dotnet. Tar. Gz# Install .NET Core
RUN dotnet_version=3.1.10 \
    # 我们不下载了,太慢,太慢~~~~
    #    && curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-linux-x64.tar.gz \
    # https://dotnetcli.blob.core.windows.net/dotnet/Runtime/3.1.10/dotnet-runtime-3.1.10-linux-x64.tar.gz
    # download slow in china ========
Copy the code

build

docker build -t centos8-dotnet31 .

Sending build Context to Docker Daemon 30.43 MB Step 1/13: FROM centos:8 ---> 0d120b6ccaa8
Step 2/13 : ENV DOTNET_CORE_VERSION 3.1 DOTNET_FRAMEWORK netcoreapp3.1 DOTNET_RUNNING_IN_CONTAINER true DOTNET_SSL_CERT_DIR /opt/app-root/ssl_dir TZ Asia/Shanghai
 ---> Using cache
 ---> 84828b8e519d
Step 3/13 : RUN yum install -y langpacks-zh_CN
 ---> Using cache
 ---> 903049fcd58c
Step 4/13 : RUN export LANG=zh_CN.UTF-8
 ---> Running in 5a59ed12a87c

 ---> d64659f24088
Removing intermediate container 5a59ed12a87c
Step 5/13 : RUN echo -e "export LANG=zh_CN.UTF-8" > /etc/locale.conf
 ---> Running in fe1ec4111a72

 ---> a1ba5fea2b3b
Removing intermediate container fe1ec4111a72
Step 6/13 : RUN echo -e "export LANG=zh_CN.UTF-8" > /etc/profile
 ---> Running in 68aecf25b603

 ---> 108ddac88adf
Removing intermediate container 68aecf25b603
Step 7/13 : RUN source /etc/profile
 ---> Running in 97f728044a65

 ---> 1ab5ceaf7b82
Removing intermediate container 97f728044a65
Step 8/13 : ENV LANG zh_CN.UTF-8
 ---> Running in d28d25a03d5b
 ---> d8ed5480d450
Removing intermediate container d28d25a03d5b
Step 9/13 : ENV LC_ALL zh_CN.UTF-8
 ---> Running in dd17f73990f9
 ---> 9dd65bcfaf72Removing Intermediate Container DD17f73990f9 Step 10/13: COPY dotnet-Runtime3.1.10-linux-x64.tar. gz dotnet.tar.gz ---> e74ea72beaa6Removing intermediate container 8ecb98769565 Step 11/13 : The RUN dotnet_version = 3.1.10 && dotnet_sha512='7ff09caf2cdff0ae1c75d0ac731267ffa624025137b079134eb9fda15e1ca386af8422ddd3e93ba084853006e7d58bc04bdf232ad 3762580e94658ce3dc8f984' && echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - && mkdir -p /usr/share/dotnet && tar -ozxf dotnet.tar.gz -C /usr/share/dotnet && rm dotnet.tar.gz && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet ---> Running in 7e2bcc123cf4

dotnet.tar.gz: OK
 ---> 66dd2f8d5681
Removing intermediate container 7e2bcc123cf4
Step 12/13 : RUN yum install  -y epel-release &&     yum install -y libgdiplus-devel &&     yum clean all -y &&     rm -rf /var/cache/yum/*
 ---> Running in ef8d63b1208cLast metadata expiration Check: 2:49:48 ago on Friday, November 13, 2020 19:55:37 SEC Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: epel-release noarch 8-8.el8 extras 23 k Transaction Summary ================================================================================ Install 1 Package Total download size: 23 k Installed size: 32 k Downloading Packages: epel-release-8-8.el8.noarch.rpm 39 kB/s | 23 kB 00:00 -------------------------------------------------------------------------------- Total 10 kB/s | 23 kB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : epel-release-8-8.el8.noarch 1/1 Running scriptlet: epel-release-8-8.el8.noarch 1/1 Verifying : epel-release-8-8.el8.noarch 1/1 Installed: epel-release-8-8.el8.noarch Complete! Extra Packages for Enterprise Linux Modular 8-9.9 kB/s | 97 kB 00:09 39 files removed ---> dfe64e392df6
Removing intermediate container 1efb1e7b5ee2
Step 13/13 : RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime     && echo ${TZ} > /etc/timezone
 ---> Running in ffc50b140330

 ---> c263956a0d45
Removing intermediate container ffc50b140330
Successfully built c263956a0d45
Copy the code

Check the container

Size when packed: 405 MB. I feel good about myself because I don’t see the Dockerfile that someone else built, this is enough of a simplification, haha ~~ go into the container and check the dotnet information

dotnet --info It was not possible to find any installed .NET Core SDKs Did you mean to run .NET Core SDK commands? Install.net Core SDK from: https://aka.ms/dotnet-download Host (Useful for support): Version: 3.1.10 Commit: 1721e39439 .NET Core SDKs installed: No SDKs were found. .NET Core runtimes installed: Microsoft.NET. The Core App 3.1.10 / / usr/share/dotnet/shared/Microsoft.NET. The Core App To install additional. NET Core runtimes or SDKs: https://aka.ms/dotnet-downloadCopy the code