Docker + Angular2 + ASP.NET Core build errors - asp.net

I'm trying to build a Docker Image from my Angular2 App that runs on ASP.Net Core. I've used the Dockerfile from https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/Dockerfile to create my Dockerfile and it almost works except for folloing error showing up when I run the image I created:
Uncaught ReferenceError: vendor_ is not defined
Therefor I assumed that the problem lies within webpack and added the following code:
RUN webpack --config webpack.config.vendor.js
But now I'm getting this error:
/bin/sh: 1: webpack: not found
After that I tried:
RUN npm install webpack -g
RUN npm install webpack-cli -g
But that keeps failing with cryptic errors like:
Error: Cannot find module 'js.clone'
That's the Dockerfile I copied for my Dockerfile and to what I added the aformentioned lines of Code:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
RUN apt-get -qq update && apt-get install -y build-essential
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g --unsafe-perm node-sass && npm rebuild --unsafe-perm node-sass -f
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Asp2017.csproj .
RUN apt-get -qq update && apt-get install build-essential -y && apt-get install -my wget gnupg && apt-get -qq -y install bzip2
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN dotnet restore ./Asp2017.csproj
COPY . .
WORKDIR /src/
RUN dotnet build Asp2017.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Asp2017.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Asp2017.dll"]
So my question is:
What is best practice for a Dockerfile for Angular2 + ASP.NET Core?
Thanks for any ideas and help!

For anyone else facing similar problems: I actually only managed to get this to work by running webpack and dotnet publish -c Release -o out before docker build ....
The new Dockerfile looks like this:
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY out .
EXPOSE 7000/tcp
ENTRYPOINT ["dotnet", "myApp.dll"]
Hope it helps!

Related

Python symbol lookup error when running PyODBC and MySQL in a Docker container. What to do?

I am trying to connect to a MySQL database using PyODBC in a Docker container. When I run the script it gives the error python: symbol lookup error: /usr/local/lib/private/libssl.so.1.1: undefined symbol: EVP_idea_cbc, version OPENSSL_1_1_0.
This is my Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.10
WORKDIR /app
COPY requirements.txt requirements.txt
ARG PYPI_USERNAME
ARG PYPI_PASSWORD
# Install PyODBC requirements
RUN apt-get update && \
apt-get -y install g++ unixodbc-dev openssl
# Install MySQL ODBC driver
ADD https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz .
RUN tar -C . -xzvf mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz
RUN cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/bin/* /usr/local/bin
RUN cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/lib/* /usr/local/lib
RUN myodbc-installer -a -d -n "MySQL ODBC 8.0 Driver" -t "Driver=/usr/local/lib/libmyodbc8w.so"
RUN myodbc-installer -a -d -n "MySQL ODBC 8.0" -t "Driver=/usr/local/lib/libmyodbc8a.so"
# Run pip as a python module to access environment variables in requirements.txt
RUN python -m pip install --no-cache-dir -r requirements.txt
COPY . .
CMD python script.py
After some research it seems to me that the issue stems not from Python but from my libraries being messed up for some reason. I tried installing openssl using apt-get but to no avail. I am at a loss as to how to proceed as this is really not my forte. Any help would be greatly appreciated!

How to install a specific version of node in a Ubuntu environment

When I docker run -it wordpress:php7.0-apache I could execute all of those following command
FROM wordpress:php7.0-apache
RUN apt-get update
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
RUN /bin/dash ~/.profile
RUN /bin/dash nvm install 8.11.4
My issue is when I try to docker build -t imageName:version I would have an error :
/bin/dash: 0: Can't open nvm
The command '/bin/sh -c /bin/dash nvm install 8.11.4' returned a non-zero code: 1277
What could be the difference ?
Thank you David Maze. Indeed there is no need of nvm to install a specific version.
My Dockerfile now :
FROM wordpress:php7.0-apache
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs

jupyter lab (not pip installed but GitHub code) not loading icons when opened via docker

I am trying to load JupyterLab (by building the GitHub source code and not installing it using 'pip'), by opening it via a docker container, but it is not loading the icons which are accessed by css variables (e.g. :- background_image = var(--jp-terminal)). To be precise only the python icons for 'Notebook' and 'Console' are loading because they are loaded by html tags. The rest are loaded by variables as mentioned before.
My current directory looks like this :-
bin docker jupyterlab
The 'bin' folder contains the 'run.sh' file, the 'docker' folder contains the 'Dockerfile' and the 'jupyter lab' folder contains the source code and files for jupyter lab taken from GitHub.
Here is my Dockerfile :-
FROM centos:latest
RUN yum -y install epel-release \
yum -y install python-devel.x86_64 python27-python-devel.x86_64 gcc \
yum -y install nodejs \
yum -y install python-pip \
yum -y install sudo
RUN pip install --upgrade setuptools pip
RUN yum -y update
COPY jupyterlab /jupyterlab
RUN cd /jupyterlab && pip install -e . && jlpm install && jlpm run build && jlpm run build:core && jupyter lab build
COPY bin/run.sh /run.sh RUN chmod +x /run.sh
EXPOSE 8888
ENTRYPOINT ["/bin/sh", "/run.sh"]
Here is the 'run.sh' file which is used as entrypoint :-
jupyter notebook --generate-config
mkdir -p -m 700 /home/jupyter/.jupyter/ && echo "c.NotebookApp.token = ''" >> /home/jupyter/.jupyter/jupyter_notebook_config.py
jupyter lab --ip=* --no-browser --allow-root
Any suggestions?

Docker NPM Install Not working

I want to expose my asp.net core application in docker. However i can't get NPM to work. I tried the following below but i get the message that NPM is not found. However i installed nodejs, so i guess it should be available.
Any idea what i'm doing wrong ?
FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr
ADD package.json /tmp/package.json
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get -y install nodejs && cd /tmp && npm install
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]
Older versions of Node did not have npm bundled with them. On some Linux distributions, the version of Node in the repository is quite old e.g. on centos it is something like 0.10.7.
It is likely that your application requires a certain version of nodejs to be installed. If this is so, you will need to add the relevant repository to your virtual machine as part of the dockerfile before running
apt-get -y install nodejs
This link gives some details of how to do this on your distribution:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.
If on the other hand you are happy with whatever version of Node your distribution has in its repo, then Suresh Koya's answer is fine.
On linux npm has to be installed separate than nodejs.
You need to add:
RUN apt-get -y install npm
http://blog.teamtreehouse.com/install-node-js-npm-linux
As you can see here:
https://hub.docker.com/r/microsoft/aspnet/~/dockerfile/
FROM mono:4.0.1
mono:4.0.1:
FROM debian:wheezy
Why do you use the jessie ?
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr
ADD package.json /tmp/package.json
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && \
apt-get -y install nodejs npm && cd /tmp && npm install && \
rm -rf /var/lib/apt/lists/*
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

Where my files exist in Docker image?

I'll switch to container based infrastructure in my Travis-CI builds. So
I wrote following commands in my Dockerfile, image was successfully built:
RUN apt-get install software-properties-common -y
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
RUN apt-get update
RUN apt-get install gcc-4.9 -y
RUN apt-get install build-essential perl python git -y
RUN apt-get install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev -y
RUN apt-get install libedit-dev -y
RUN apt-get install flex bison gperf libicu-dev libxslt-dev -y
RUN git clone git://code.qt.io/qt/qt5.git qt5
RUN cd qt5 && perl init-repository
RUN unset QTDIR
RUN export PATH="$PWD/qtbase/bin:$PWD/qtrepotools/bin:$PATH"
RUN cd qt5 && ./configure -developer-build -opensource -confirm-license -nomake examples -nomake tests
RUN cd qt5 && make
RUN cd qt5 && make install
RUN git clone git://code.qt.io/qt-creator/qt-creator.git qt-creator
RUN mkdir qt-creator-build
RUN cd qt-creator-build
RUN ../qt5/qtbase/bin/qmake -r ../qt-creator/qtcreator.pro
RUN make -j5
Before I push it to Docker Hub I need to know where is my stuff was created in the image. I need something like map of my files for getting access from Travis-CI. Please help me to understand. Thanks
UPD: actually, I need only an absolute path of qt-creator-build folder.
Based on your commands, the absolute path to the qt-creator-build folder should be /qt-creator-build, as the root directory / is the default working directory for every docker command.
That said, the command RUN make -j5 should probably be RUN cd qt-creator-build && make -j5, but only if you actually want to run make -j5 inside qt-creator-build, and that's what I understood from your code.
From the docs of Docker, you can use the WORKDIR command to change de working directory, like:
WORKDIR qt-creator-build

Resources