Asp.net 5 - Docker - docker

I'm about to lose my head ;-)
I've tried all tutorials I can find on running ASP.NET 5 using Docker in Linux.
It won't work....
I'm using Ubuntu 14.04 no matter what I do I always get :
mountpoint for devices not ready.
For some Dockerfile setup I'll get this message in build for other configuration I'll get it on run.
There is no point to shave my Dockerfile because I had tens of them.
I'm using Windows 10 Hyper-V for the virualization
Dockerfile
FROM microsoft/aspnet:1.0.0-rc1-final
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5000
ENTRYPOINT ["dnx","-p", "project.json", "kestrel"]
Build - docker build -t dev3 .
Run - docker run -t -d -p 87:5000 dev3
Docker Install - apt-get install docker.io

Im running ASP.NET 5 in docker on ubuntu 15.04, I noticed in my Dockerfile im using this image:
FROM microsoft/aspnet:1.0.0-rc1-final-coreclr
You could try using that image, but it sounds like its your Docker install.

Related

Docker - dotnet build can't find file

I am trying to make my application work in a Linux container. It will eventually be deployed to Azure Container Instances. I have absolutely no experience with containers what so ever and I am getting lost in the documentation and examples.
I believe the first thing I need to do is create a Docker image for my project. I have installed Docker Desktop.
My project has this structure:
MyProject
MyProject.Core
MyProject.Api
MyProject.sln
Dockerfile
The contents of my Dockerfile is as follows.
#Use Ubuntu Linux as base
FROM ubuntu:22.10
#Install dotnet6
RUN apt-get update && apt-get install -y dotnet6
#Install LibreOffice
RUN apt-get -y install default-jre-headless libreoffice
#Copy the source code
WORKDIR /MyProject
COPY . ./
#Compile the application
RUN dotnet publish -c Release -o /compiled
#ENV PORT 80
#Expose port 80
EXPOSE 80
ENTRYPOINT ["dotnet", "/compiled/MyProject.Api.dll"]
#ToDo: Split build and deployment
Now when I try to build the image using command prompt I am using the following command
docker build - < Dockerfile
This all processed okay up until the dotnet publish command where it errors saying
Specify a project or solution file
Now I have verified that this command works fine when run outside of the docker file. I suspect something is wrong with the copy? Again I have tried variations of paths for the WORKDIR, but I just can't figure out what is wrong.
Any advice is greatly appreciated.
Thank you SiHa in the comments for providing a solution.
I made the following change to my docker file.
WORKDIR app
Then I use the following command to build.
docker build -t ImageName -f FileName .
The image now creates successfully. I am able to run this in a container.

Docker does not build image

I just got started with docker and was following fireship's tutorial, however I encountered a problem when I ran the docker build command. I was expecting a similar output as the video (timestamp). Instead, I got the following:
Dockerfile
FROM node:12
WORKDIR /app #maybe its this? There is no /app directory
COPY package*.json ./
RUN npm install
COPY . .
ENV PORT=8080
EXPOSE 8080
CMD ["npm","start"]
docker build command
docker build -t <my docker id>/firstapp:1.1 .
File tree
D:/
Code/
testing/
Docker/
test1/
Notes
Yes, I have a docker ID.
The docker build command stopped at COPY . ., rather than finishing at CMD ["npm","start"]
CWD (Windows): D:\Code\testing\Docker\test1
I ran the docker build command twice
Questions
Why is this happening?
How can it be fixed?
The reason this occurs is because fireship is running Linux (like Hans Kilian noted) and I am running Windows. To get your image ID, run the docker images command, which will list your images w/ their image ID.
However, I am still not sure why it does not complete all 8 steps.

Can not run docker container from compose

I can not run a Net Core application in docker-compose due to this error,while i can start the container from dockerfile.
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
My dockerfile uses the .dll directly (i am directly using the publish directory), so no build ,restore is required.
FROM microsoft/dotnet:aspnetcore
WORKDIR /app
COPY ./publish .
ENTRYPOINT ["dotnet", "Server.dll"]
EXPOSE 8202
I run:
docker build -t mp .
docker run --name mp0 -d myimg and it works.
However when i am running it from compose :
mp:
image: mp
container_name: mp0
build: ./mpbuild
ports:
- 8302:8202
I have tried using :aspnetcore,aspnetcore-build,aspnetcore-runtime to no avail .I keep getting asked about the SDK.
P.S: The app is version aspnetcore 2.1.
try changing microsoft/dotnet:aspnetcore to microsoft/dotnet:2.2-sdk

Running simple Java Gradle app in Docker

I have a simple Java server app with a Gradle build. It works perfectly with gradle run on my host machine. However, I want to build this in a docker image and run as a docker container.
I'm using docker-machine (version 0.13.0):
docker-machine create --driver virtualbox --virtualbox-memory 6000 default
docker-machine start
eval $(docker-machine env default)
I have the following Dockerfile image build script in ./serverapp/Dockerfile:
FROM gradle:4.3-jdk-alpine
ADD . /code
WORKDIR /code
CMD ["gradle", "--stacktrace", "run"]
I can build perfectly:
➜ docker build -t my-server-app .
Sending build context to Docker daemon 310.3kB
Step 1/4 : FROM gradle:4.3-jdk-alpine
---> b803ec92baec
Step 2/4 : ADD . /code
---> Using cache
---> f458b0be79dc
Step 3/4 : WORKDIR /code
---> Using cache
---> d98d04eda627
Step 4/4 : CMD ["gradle", "--stacktrace", "run"]
---> Using cache
---> 869262257870
Successfully built 869262257870
Successfully tagged my-server-app:latest
When I try to run this image:
➜ docker run --rm my-server-app
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.internal.service.ServiceCreationException: Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:797)
<snip>
... 60 more
Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/code/.gradle/4.3' when creating directory '/code/.gradle/4.3/fileHashes'
at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:271)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:56)
Why would it have trouble creating that directory?
This should be a very easy task, can anyone tell me how they get this simple scenario working?
FYI, running current versions of everything. I'm using Gradle 4.3.1 on my host, and the official Gradle 4.3 base image from docker hub, I'm using the current version of JDK 8 on my host and the current version of docker, docker-machine, and docker-compose as well.
The fix was to specify --chown=gradle permissions on the /code directory in the Dockerfile. Many Docker images are designed to run as root, the base Gradle image runs as user gradle.
FROM gradle:4.3-jdk-alpine
ADD --chown=gradle . /code
WORKDIR /code
CMD ["gradle", "--stacktrace", "run"]
Ethan Davis suggested using /home/gradle rather than code. That would probably work as well, but I didn't think of that.
The docker image maintainer should have a simple getting started type reference example that shows the recommended way to get basic usage.
Based on the openjdk base image to the gradle image we can see that gradle projects are setup to run in /home/gradle. Check the code out here. gradle run is having trouble running in your new working directory, /code, because the .gradle folder is in the /home/gradle folder. If you copy/add your code into /home/gradle you should be able to run gradle run. This worked for me.

Running .net core docker image, says application started, but on browsing gives "This site can’t be reached" error

I am having Windows 10 Home operating system. I have installed Docker toolbox.
My docker file is as follows:
FROM microsoft/dotnet:1.1-sdk-projectjson
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "run"]
I have created docker image by using following command:
$ docker build -t test:webApp3 .
I tried running the image by using following commands:
$ docker run -d -p 8080:5000 -t test:webApp3
$ docker run test:webApp3
Command says application started, but on browsing gives "This site can’t be reached" error.
Can someone please tell me, why its giving me specified error?
Plus can someone tell me, where does docker save created images on Windows 10 OS?
I was able to fix this by referring to following link:
https://medium.com/trafi-tech-beat/running-net-core-on-docker-c438889eb5a#.s3krizvtw
I was required to add, .UseUrls("http://*:5000/") in Main() of Program.cs.
Then I was able to browse, by using following URL:
http://192.168.99.100:5000/api/values

Resources