Docker container exits immediately in Linux Server - docker

I have built an image with simple ASP .NET Core 2.0 App in Alpine Docker. When I run the Linux container on Windows Power-Shell, everything is fine. But if I run the Linux container on a Linux Server in PuTTY, the container will immediately exit with code 139. I have used the following conmmand:
docker run -it -d -p xxxx:80 imageName
output:
510e77c3899696823d4f1fba135cbaff3f8b4232deb1a73d41963fc3a8058d81
run without -d
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
OS: Win 10
Docker Version:
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
Is there a way to keep the container alive? Did I miss anything important? Any ideas would be appreciated!
Update Dockerfile:
#build image
FROM microsoft/dotnet:2.1-sdk as builder
WORKDIR /app
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish --output /out/ --configuration Release
# runtime image
FROM microsoft/dotnet-nightly:2.1-runtime-alpine AS runtime
RUN apk add --no-cache libuv \
&& ln -s /usr/lib/libuv.so.1 /usr/lib/libuv.so
ENV ASPNETCORE_URLS http://+:80
WORKDIR /app
COPY --from=builder /out .
ENTRYPOINT ["dotnet", "WebAppHelloWorld.dll"]

Related

How to build docker image, using a dockerfile from stdin with shell varaibles

I try to build a docker image with Jenkins, using here docuemnt. Part of the The shell:
# Docker image build.
mkdir -p "$BASE_PATH/.docker"
cd "$BASE_PATH/.docker"
echo "docker version: "
docker version
docker login --username=****** --password ****** ******
docker build -t "******/$DOCKER_IMAGE" -f- . <<EOF
FROM ******
ARG NGINX_CONF_FILE=$NGINX_CONF_FILE
ENV DEPLOY_PATH=$DEPLOY_PATH
ENV NGINX_CONF_DIR=$NGINX_CONF_DIR
RUN mkdir -p \$DEPLOY_PATH \\
&& chmod 777 "\$DEPLOY_PATH"
WORKDIR \$DEPLOY_PATH
ADD customer customer/
ADD mall mall/
ADD marketing marketing/
ADD portal portal/
ADD setup setup/
ADD store store/
ADD work work/
WORKDIR \$NGINX_CONF_DIR
COPY ./\$NGINX_CONF_FILE .
EXPOSE 8000
EOF
When running it with bash, Jenkins complains:
docker version:
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: 0801b25
Built: Tue Mar 28 08:29:28 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: 0801b25
Built: Tue Mar 28 08:29:28 2017
OS/Arch: linux/amd64
Experimental: false
Login Succeeded
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/jenkins_home/workspace/docker-test-scrmv3/.docker/-: no such file or directory
Build step 'Execute shell' marked build as failure
New run name is '#17 ver:0.0.17'
Finished: FAILURE
Looks like docker treat the hyphen (-) as a directory not stdin. Accroding to the offical recommand this should work but dont know how. Any way to fix it?
Docker should be above 17.05. The document not metion it.

How to reduce asp.net core project docker runtime image size

I've just added a Dockerfile to my simple asp.net core demo project.
When i run
docker build -f .\deploy\Dockerfile -t coreapp .
It results in a image of 1,35GB..
Docker version (docker for windows)
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:21:34 2018
OS/Arch: windows/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.24)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:36:40 2018
OS/Arch: windows/amd64
Experimental: false
Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /build
COPY . /build
#Restore
RUN dotnet restore ./WebAppDockerDemo.sln
RUN dotnet publish ./src/WebApp/WebApp.csproj --output /publish --configuration Release
# Build runtime image
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /publish/ .
ENTRYPOINT ["dotnet", "WebApp.dll"]
Why is the image so large? I thought the runtime image I create would be around 2-300MB.. I checked different examples, 1, but can't find what's wrong here.
How can I reduce the size?

unable to send request to .net core app hosted with docker

I have create default VS2017 webAPI project with docker support for Linux.
When i had try to build image I met problem like "unable to find .../docker-buildxxxx/" , to solve it i moved dockerfile on one level up, where is *.sln and .dockerignore file are.
I had successfully build and run that image, but i have no luck to take some request into container. I use -p host_port:container_port in all possible combinations, but it is useless.
FYI: without docker it works fine. (dotnet test.dll)
Can you provide some point where i have to research or can you provide exact solution ?
docker version
Client: Docker Engine - Community
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:47:51 2018
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:52:55 2018
OS/Arch: linux/amd64
Experimental: false
docker run -t service --port 8080:80 --name myfirst_container
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {71f5b198-2cbb-45ba-a7fc-a36df9f8b985} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
DOCKERFILE
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["test/test.csproj", "test/"]
RUN dotnet restore "test/test.csproj"
COPY . .
WORKDIR "/src/test"
RUN dotnet build "test.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "test.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "test.dll"]
It was the two hardest nights in my life, but i get a solution.
Problem was caused by Visual studio, it generate wrong dockerfile.
Fixed dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY test/*.csproj ./test/
RUN dotnet restore
# copy everything else and build app
COPY test/. ./test/
WORKDIR /app/test
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/test/out ./
ENTRYPOINT ["dotnet", "test.dll"]
Solution came from here:
https://hub.docker.com/r/microsoft/dotnet-samples/
https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile

Docker: Win container: The application to execute does not exist

I am trying to create my first docker image and container.
I follow documents / videos I found online.
On my Microsoft Windows 10 Pro - 10.0.16299 Build 16299 I can successfully build ASP.NET Core application after running command docker build -t web ..
But when I try to run image docker run -ti web, I get error:
The application to execute does not exist: 'C:\app\Web.dll'
Is there any command to list files? I want to check path and where (if) dll exists. I couldn't find such command on web.
Also any hint where to look for problem would be awesome. Also (if it helps) docker ps doesn't list anything.
Docker:
Client:
Version: 18.02.0-ce
API version: 1.36
Go version: go1.9.3
Git commit: fc4de44
Built: Wed Feb 7 21:12:53 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.02.0-ce
API version: 1.36 (minimum version 1.24)
Go version: go1.9.3
Git commit: fc4de44
Built: Wed Feb 7 21:26:24 2018
OS/Arch: windows/amd64
Experimental: true
Dockerfile:
# Stage 1
FROM microsoft/aspnetcore-build AS builder
WORKDIR /source
# caches restore result by copying csproj file separately
COPY Web.sln ./src/aspdocker/Web.sln
COPY Web.Library/Web.Library.csproj ./src/aspdocker/Web.Library/
COPY Web.Core/Web.Core.csproj ./src/aspdocker/Web.Core/
COPY Web.Hosting/Web.Hosting.csproj ./src/aspdocker/Web.Hosting/
COPY Web.Library.Tests/Web.Library.Tests.csproj ./src/aspdocker/Web.Library.Tests/
COPY Web.Core.Tests/Web.Core.Tests.csproj ./src/aspdocker/Web.Core.Tests/
# caches restore result by copying csproj file separately
RUN dotnet restore ./src/aspdocker/Web.sln
# copies the rest of your code
COPY . .
RUN dotnet publish --output /app/
# Stage 2
#FROM microsoft/aspnetcore:1.1.2
FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=builder /app .
#EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "Web.dll"]

Docker: Unable to execute RUN command after ADD when starting from scratch

I'm trying to build a custom Linux Alpine docker for ARM architecture starting from the "scratch" image. I don't understand why I can't execute any RUN command after I execute ADD. This is my Dockerfile:
FROM scratch
ADD rootfs.tar /
MAINTAINER Vittorio_Cozzolino
RUN apk add nodejs
And this is the output that I get when the automated build completes (the last line contains the error):
Client: Version: 1.8.1 API version: 1.20 Go version:
go1.4.2 Git commit: d12ea79 Built: Thu Aug 13 02:49:29 UTC
2015 OS/Arch: linux/amd64
Server: Version: 1.8.3-rc1 API version: 1.20 Go version:
go1.4.2 Git commit: 6f21aba Built: Mon Sep 28 20:03:03 UTC
2015 OS/Arch: linux/amd64 Step 0 : FROM scratch
---> Step 1 : ADD rootfs.tar /
---> dd771ffd56ea702 Step 2 : MAINTAINER Vittorio_Cozzolino
---> 825fc4c990c8a33 Step 3 : RUN apk add nodejs [91mexec: "/bin/sh": stat /bin/sh: no such file or directory
Actually /bin/sh exists and, in fact, if I run CMD ["/bin/sh"] I don't get any error. Can anyone help me here?
CMD ["/bin/sh"] is a simple declaration of the default command to run, so it will always work.
Check if the tar is indeed unpacked, as there was a similar issue in 9541: limit your Dockerfile to the ADD directive, and use docker exec or a simple ls to see what is in there (and with which owner/permission).
If the Dockerfile complains about a missing /bin/sh, and /bin/sh is in the tar archive... chances are that archive didn't uncompress properly.

Resources