0
votes

I am trying to create a docker image that I can pack an aspnetcore2.0/angular-universal application and due to my insufficient docker experience I been keep running into issues. I could really use some help.

Here is the dockerfile content:

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app

COPY *.csproj ./
RUN npm cache clean --force
RUN npm install npm@latest
RUN npm install @angular/cli@latest
RUN npm install @ngtools/webpack@next
RUN node -v
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM microsoft/microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "net-streetStyleCrew.dll" ]

since the aspnetcore-build:2.0 comes with a too old npm/node it has to be updated. And it have not go to angular-cli part, but i assume that need to be fresh as well of course. And here is the trouble that I am running into now, and i have no clue how to resolve what appears to be a network issue inside the container when attempts to update:

Step 5/15 : RUN npm install npm@latest
 ---> Running in 72531196fc83
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "npm@latest"
npm ERR! node v6.13.0
npm ERR! npm  v3.10.10
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! syscall getaddrinfo

npm ERR! network getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR!     C:\app\npm-debug.log
The command 'cmd /S /C npm install npm@latest' returned a non-zero code: 1 

I am trying to run this on a windows container, because I don't have a whole lot of experience with Linux either.

I am absolutely open to any suggestion as well that could improve my approach to the basic concept. Thanks in advance.

1

1 Answers

1
votes

Firstly, I think the specific issue is not a Docker related issue. This is a network related issue. Maybe this SO thread will help.

Regarding your Dockerfile:

  1. The official best practice recommends reducing the number of layers. Each RUN command creates a layer. At the same time, you may want to have multiple RUN command to improve readability and take the benefit of caching. So, you need to find a balance between the two. In this particular case, I think you should chain the npm commands in a single RUN statement.
  2. Also, I think instead of using the latest version, you should specify the exact version. The latest will always download the latest at the time of image creation and you don't know whether this new version is having a bug that breaks your app. So, the idea is to test in a specific version and use that same version in production. If you want to upgrade later to more recent version, you need to first test your app with the new version and then update your Dockerfile with the new version

Here is an e.g.

RUN mkdir /home/aus/.npm; \
npm config set prefix /home/aus/.npm; \
npm install --quiet --no-progress -g [email protected]; \
npm install --quiet --no-progress -g @angular/[email protected]; \
npm install --quiet --no-progress;