slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)
Apache License 2.0
19.26k stars 718 forks source link

Show logs eagerly instead of lazily #105

Open jyn514 opened 4 years ago

jyn514 commented 4 years ago

I'm trying to build a Dockerfile I normally run with docker-compose, so there's lots of arguments that I keep forgetting to add (--mount, --env, etc.). It's painful to troubleshoot this because I have to wait for docker-slim to make five tries and timeout before I can see what the error is. Would it be possible to show the logs from --show-clogs immediately, after the first HTTP failure?

Current output:

docker-slim[build]: info=container name=dockerslimk_17520_20191212010301 id=e6285282f34f2ed3a00152b847a3078719fa04173448724d842d18769fe8df7c target.port.list=[32794] target.port.info=[3000/tcp => 0.0.0.0:32794] message='YOU CAN USE THESE PORTS TO INTERACT WITH THE CONTAINER'
docker-slim[build]: state=http.probe.starting message='WAIT FOR HTTP PROBE TO FINISH'
docker-slim[build]: info=continue.after mode=probe message='no input required, execution will resume when HTTP probing is completed'
docker-slim[build]: info=prompt message='waiting for the HTTP probe to finish'
docker-slim[build]: state=http.probe.running
docker-slim[build]: info=http.probe.ports count=1 targets='32794'
docker-slim[build]: info=http.probe.commands count=1 commands='GET /'
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=1 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56516->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:14Z
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=2 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56524->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:22Z
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=3 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56546->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:30Z
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=4 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56552->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:38Z
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=5 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56556->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:46Z
docker-slim[build]: info=http.probe.summary total=5 failures=5 successful=0
docker-slim[build]: state=http.probe.done warning=no.successful.calls
docker-slim[build]: info=event message='HTTP probe is done'
docker-slim[build]: state=container.inspection.finishing
docker-slim: container stdout:
docker-slim: container stderr:
time="2019-12-12T01:03:02Z" level=info msg="sensor: args => []string{\"/opt/dockerslim/bin/docker-slim-sensor\"}"
time="2019-12-12T01:03:02Z" level=info msg="sensor: waiting for commands..."
time="2019-12-12T01:03:02Z" level=info msg="sensor: monitor starting..."
time="2019-12-12T01:03:02Z" level=info msg="fanmon: Run"
time="2019-12-12T01:03:02Z" level=info msg="ptmon: Run"
... the output from my container ...

Requested output:

docker-slim[build]: info=container name=dockerslimk_17520_20191212010301 id=e6285282f34f2ed3a00152b847a3078719fa04173448724d842d18769fe8df7c target.port.list=[32794] target.port.info=[3000/tcp => 0.0.0.0:32794] message='YOU CAN USE THESE PORTS TO INTERACT WITH THE CONTAINER'
docker-slim[build]: state=http.probe.starting message='WAIT FOR HTTP PROBE TO FINISH'
docker-slim[build]: info=continue.after mode=probe message='no input required, execution will resume when HTTP probing is completed'
docker-slim[build]: info=prompt message='waiting for the HTTP probe to finish'
docker-slim[build]: state=http.probe.running
docker-slim[build]: info=http.probe.ports count=1 targets='32794'
docker-slim[build]: info=http.probe.commands count=1 commands='GET /'
docker-slim[build]: info=http.probe.call status=error method=GET target=http://127.0.0.1:32794/ attempt=1 error='Get http://127.0.0.1:32794/: read tcp 127.0.0.1:56516->127.0.0.1:32794: read: connection reset by peer' time=2019-12-12T01:03:14Z
docker-slim: container stdout:
docker-slim: container stderr:
time="2019-12-12T01:03:02Z" level=info msg="sensor: args => []string{\"/opt/dockerslim/bin/docker-slim-sensor\"}"
time="2019-12-12T01:03:02Z" level=info msg="sensor: waiting for commands..."
time="2019-12-12T01:03:02Z" level=info msg="sensor: monitor starting..."
time="2019-12-12T01:03:02Z" level=info msg="fanmon: Run"
time="2019-12-12T01:03:02Z" level=info msg="ptmon: Run"
... the output from my container ...
... all the other output I pasted above ...
kcq commented 4 years ago

@jyn514 thank you for creating the issue! I hear a number of potential opportunities for improvement... Showing the container logs lines as they become available is one of them. Sounds like it might also be good to have extra login to guess if some of the parameters are missing... Can you share the final command line with docker-slim? It'll be super helpful. Also sounds like it might be more convenient to have an ability to point docker-slim to an existing docker-compose service profile, so it can figure out the parameters it should use.

jyn514 commented 4 years ago

@kcq Sure thing, although I'm not sure how helpful it will be ...

sudo $(which docker-slim) build --expose 3000 --show-clogs --network docsrs_default \
   --env CRATESFYI_DATABASE_URL=postgresql://cratesfyi:password@db \
   --env CRATESFYI_RUSTWIDE_WORKSPACE=/opt/docsrs/rustwide \
   --mount "/var/run/docker.sock:/var/run/docker.sock" \
   --mount "$(realpath .rustwide-docker):/opt/docsrs/rustwide" \
   --mount "cratesio-index:/opt/docsrs/prefix/crates.io-index" \
   docsrs_web
jyn514 commented 4 years ago

As you can see it's a pretty complicated setup :laughing: I think reading from docker-compose.yml files would be more helpful than 'did you forget a parameter' - you already said this and I didn't read lol

jyn514 commented 4 years ago

Also this command line is not currently working, it's just as far as I got it before giving up :/ Let me point you to the actual repo I'm running this on: https://github.com/rust-lang/docs.rs This also requires running docker-compose up db in a separate terminal.

jyn514 commented 4 years ago

I said it wasn't working, but now that I try again it seems to be working fine ... I think the issue is it has a fairly lengthy setup period but docker-slim tries to access the HTTP server immediately. Once I'd run it a couple times it finished initializing and the requests got though.