Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Container exits after starting / Sample docker file #58

Closed
yngndrw opened this issue May 16, 2015 · 7 comments
Closed

Container exits after starting / Sample docker file #58

yngndrw opened this issue May 16, 2015 · 7 comments
Labels

Comments

@yngndrw
Copy link

yngndrw commented May 16, 2015

I've been trying to get this to work with a standard empty project from the Visual Studio ASP.Net 5 templates. This template generates the following kind of structure: (I also added the kestrel command and dependency to the project.json file as this isn't there by default - Here's what I've ended up with: https://github.com/yngndrw/ASPNetTest)

ASPNetTest.sln
global.json
src/
src/ASPNetTest/
src/ASPNetTest/ASPNetTest.xproj
src.ASPNetTest/project.json

There wasn't an example Dockerfile on here that I could find so the first Dockerfile example that I saw from a blog was:

FROM microsoft/aspnet:1.0.0-beta4
ADD . /app
WORKDIR /app
RUN ["dnu", "restore"]

EXPOSE 5004
ENTRYPOINT ["dnx", "./src/HelloMvc6", "kestrel"]

I changed the project path and this deployed the whole solution only to find the container was exiting right after it started. It looks like the following command is used to start the container:

id=$(docker run -d -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD)

In this case, $port is "5000", $DOCKER_ARGS and $STARG_CMD are both empty and $IMAGE is an image built from my repository.

The main point of interest is -d meaning that it will be running as a background process. If I add -t, the container doesn't automatically shut down but I'm unsure as to why it helps. It also seems like a strange configuration, I thought -t would normally only be combined with -i.

I then found a different example in an old issue on here and tried the following:

FROM microsoft/aspnet:1.0.0-beta4

ADD . /app
WORKDIR /app

RUN dnu restore

EXPOSE 5000
ENV DNX_TRACE 1
ENTRYPOINT sleep 1000 | dnx ./src/ASPNetTest kestrel

This with the standard docker options (I.e. without -t) allowed my container to run for a while, but it exited after approximately an hour. Sadly I forgot to check the logs but will do when I next get a chance to.

Can anybody recommend a good Dockerfile setup to use ?

@yngndrw
Copy link
Author

yngndrw commented May 16, 2015

Just managed to get some logs although it didn't last an hour this time. This was with -t in the Docker options so it just seems to make it last a little longer:

dhc-user@cloud:~$ sudo docker logs -ft 2924bb3b522e
2015-05-16T15:46:44.232691836Z Information: [DefaultHost]: Project path: /app/src/ASPNetTest
2015-05-16T15:46:44.233315344Z Information: [DefaultHost]: Project root: /app
2015-05-16T15:46:44.234068360Z Information: [DefaultHost]: Packages path: /root/.dnx/packages
2015-05-16T15:46:44.375788794Z Information: [Breadcrumbs] Breadcrumbs for servicing will not be written because the breadcrumbs folder () does not exist.
2015-05-16T15:46:44.379536005Z Information: [DependencyWalker]: Walking dependency graph for 'ASPNetTest DNX,Version=v4.5.1'.
2015-05-16T15:46:44.494943434Z Information: [WalkContext]: Graph walk stage 1 took in 103ms
2015-05-16T15:46:44.522307272Z Information: [DependencyWalker]: Graph walk took 141ms.
2015-05-16T15:46:44.613782207Z Information: [WalkContext]: Populate took 80ms
2015-05-16T15:46:44.614752447Z Information: [DependencyWalker]: Resolved dependencies for ASPNetTest in 235ms
2015-05-16T15:46:44.635241073Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Hosting
2015-05-16T15:46:44.655544511Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Hosting in 19ms
2015-05-16T15:46:44.677568863Z Information: [LoaderContainer]: Load name=Microsoft.Framework.ConfigurationModel
2015-05-16T15:46:44.680085780Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.ConfigurationModel in 2ms
2015-05-16T15:46:44.682590270Z Information: [LoaderContainer]: Load name=Microsoft.Framework.ConfigurationModel.Interfaces
2015-05-16T15:46:44.685323294Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.ConfigurationModel.Interfaces in 2ms
2015-05-16T15:46:44.687581648Z Information: [LoaderContainer]: Load name=Microsoft.Framework.Logging.Interfaces
2015-05-16T15:46:44.690105296Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.Logging.Interfaces in 2ms
2015-05-16T15:46:44.694585112Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Http
2015-05-16T15:46:44.696967923Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Http in 2ms
2015-05-16T15:46:44.699419898Z Information: [LoaderContainer]: Load name=Microsoft.Framework.DependencyInjection.Interfaces
2015-05-16T15:46:44.702179967Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.DependencyInjection.Interfaces in 2ms
2015-05-16T15:46:44.704341420Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Hosting.Interfaces
2015-05-16T15:46:44.706888677Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Hosting.Interfaces in 2ms
2015-05-16T15:46:44.709612827Z Information: [LoaderContainer]: Load name=Microsoft.Framework.DependencyInjection
2015-05-16T15:46:44.712003230Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.DependencyInjection in 2ms
2015-05-16T15:46:44.769276055Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.FileProviders.Interfaces
2015-05-16T15:46:44.771693355Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.FileProviders.Interfaces in 2ms
2015-05-16T15:46:44.779394177Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.FileProviders
2015-05-16T15:46:44.782326854Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.FileProviders in 2ms
2015-05-16T15:46:44.782769810Z Information: [LoaderContainer]: Load name=Microsoft.Framework.Caching.Interfaces
2015-05-16T15:46:44.785717642Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.Caching.Interfaces in 2ms
2015-05-16T15:46:44.823982218Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.FeatureModel
2015-05-16T15:46:44.827249341Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.FeatureModel in 3ms
2015-05-16T15:46:44.843223919Z Information: [LoaderContainer]: Load name=ASPNetTest
2015-05-16T15:46:44.854557270Z Information: [ProjectLibraryExportProvider]: GetLibraryExport(ASPNetTest, DNX,Version=v4.5.1, Debug, )
2015-05-16T15:46:44.892939778Z Information: [Microsoft.Framework.Runtime.Roslyn.RoslynProjectReferenceProvider]: GetProjectReference(ASPNetTest, DNX,Version=v4.5.1, Debug, )
2015-05-16T15:46:44.912675042Z Information: [ProjectExportProviderHelper]: Resolving references for 'ASPNetTest'
2015-05-16T15:46:44.983648846Z Information: [ProjectExportProviderHelper]: Resolved 37 references for 'ASPNetTest' in 70ms
2015-05-16T15:46:45.096442486Z Information: [RoslynCompiler]: Compiling 'ASPNetTest'
2015-05-16T15:46:45.571466115Z Information: [LoaderContainer]: Load name=System.Security.Cryptography.Hashing
2015-05-16T15:46:45.583659020Z Information: [LoaderContainer]: Load name=System.Security.Cryptography.Hashing.Algorithms
2015-05-16T15:46:47.862237852Z Information: [RoslynCompiler]: Compiled 'ASPNetTest' in 2765ms
2015-05-16T15:46:47.880912834Z Information: [CompilationContext]: Generating resources for ASPNetTest
2015-05-16T15:46:47.895221909Z Information: [CompilationContext]: Generated resources for ASPNetTest in 14ms
2015-05-16T15:46:47.896256425Z Information: [RoslynProjectReference]: Emitting assembly for ASPNetTest
2015-05-16T15:46:47.899695120Z Warning: PDB generation is not supported on this platform
2015-05-16T15:46:53.123474366Z Information: [RoslynProjectReference]: Emitted ASPNetTest in 5227ms
2015-05-16T15:46:53.137955600Z Information: [ProjectAssemblyLoader]: Loaded name=ASPNetTest in 8293ms
2015-05-16T15:46:53.250708067Z Information: [LoaderContainer]: Load name=Microsoft.Framework.Logging
2015-05-16T15:46:53.253554339Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.Logging in 2ms
2015-05-16T15:46:53.366170008Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Http.Core
2015-05-16T15:46:53.369171538Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Http.Core in 2ms
2015-05-16T15:46:53.384987742Z Information: [LoaderContainer]: Load name=Kestrel
2015-05-16T15:46:53.387352670Z Information: [NuGetAssemblyLoader]: Loaded name=Kestrel in 1ms
2015-05-16T15:46:53.393717526Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Http.Interfaces
2015-05-16T15:46:53.395963901Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Http.Interfaces in 1ms
2015-05-16T15:46:53.436004736Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Http.Extensions
2015-05-16T15:46:53.438661706Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Http.Extensions in 2ms
2015-05-16T15:46:53.450091081Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Diagnostics
2015-05-16T15:46:53.452784757Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Diagnostics in 2ms
2015-05-16T15:46:53.478019150Z Information: [LoaderContainer]: Load name=Microsoft.AspNet.Server.Kestrel
2015-05-16T15:46:53.480602522Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.AspNet.Server.Kestrel in 2ms
2015-05-16T15:46:53.665233356Z Started
2015-05-16T15:46:57.969467464Z Information: [LoaderContainer]: Load name=Microsoft.Framework.WebEncoders.Core
2015-05-16T15:46:57.972081726Z Information: [NuGetAssemblyLoader]: Loaded name=Microsoft.Framework.WebEncoders.Core in 2ms
2015-05-16T16:03:22.194925619Z Information: [ApplicationShutdown]: Requesting shutdown.
2015-05-16T16:03:22.250706764Z Information: [ApplicationShutdown]: Requested shutdown.
dhc-user@cloud:~$ sudo docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                CREATED             STATUS                      PORTS               NAMES
2924bb3b522e        dokku/aspnettest:latest                "/bin/sh -c 'sleep 1   17 minutes ago      Exited (0) 28 seconds ago                       romantic_fermat
ca609d9c170d        dokku/node-js-getting-started:latest   "/start web"           22 hours ago        Up 22 hours                                     compassionate_lovelace
dhc-user@cloud:~$

As you can see, you just end up with "Requesting shutdown." from somewhere.

@ahmetb
Copy link
Contributor

ahmetb commented May 16, 2015

So you had

sleep 1000 | dnx ....

And sleep was keeping the dnx awake (because otherwise kestrel server waits for keyboard input and just dies within seconds). Your server died precisely 1000 seconds later. So if you do

sleep 9999999999 | dnx

It will live much longer. Keyboard requirement is a known problem and will be fixed in the next release: aspnet/Hosting#255

@yngndrw
Copy link
Author

yngndrw commented May 16, 2015

Thanks Ahmet, I didn't know that was a currently outstanding issue and wasn't sure exactly what the sleep was for.

@ahmetb
Copy link
Contributor

ahmetb commented May 16, 2015

Does this solve your problem for now?

@vlesierse
Copy link
Contributor

Finally we get rid of the nasty sleep ... workaround.

@davidfowl
Copy link
Member

😄

@yngndrw
Copy link
Author

yngndrw commented May 16, 2015

I've just pushed up a build with that, will report back once it has been up for a while.

Update: Seems to be working do far. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants