Comments (12)
Hi @Haegi and thank you for the report.
There is a number of ways to debug failing containers (which you correctly identified):
WithDebugMode
will print internal logs and prevent automatic container removalWithLogWriter
will send internal container logs to the provided writer (such asos.Stdout
) so you can save the logs regardless of final container state.
In case of busybox
, the container you start exits immediately with code zero, so there is nothing to wait for and to use later, therefore the no such container
error.
I can confirm though that the containers that exit successfully are removed regardless of WithDebugMode
, and this probably should be fixed. If you can, maybe you could think about a proper solution? Otherwise I'll try to look into it during this or one of the following weekends. Thanks!
from gnomock.
Hi @orlangure , thanks for the fast response and explanation.
Unfortunately, I am not using busybox
but some custom container. The busybox was just some example.
But with the custom container the same happens.It exists immediately. But just in CI and not on my local machine. That means that the container exists for some reason but I donβt know why and it would be nice to at least see the logs.
Maybe the WithDebugMode
or WithDisableAutoCleanup()
should not cleanup successful containers. That would be already very helpful.
Some additional option would be maybe to forward the logs of the immediately exiting container. But I am not sure if this is easily possible because it seems like the code currently is first doing the waitForContainerNetwork
/ContainerInspect
before forwarding the logs. And then the container is already cleaned up.
from gnomock.
@Haegi use WithLogWriter
to see all the logs immediately as soon as they appear. If your container prints something, you'll see it.
from gnomock.
Maybe I am missing something but the following command doesn't show anything. But only Error running container: can't start container: container network isn't ready: can't inspect container xxx: Error: No such container: xxx
_, err := gnomock.StartCustom("busybox", gnomock.DefaultTCP(5000),
gnomock.WithLogWriter(os.Stdout), gnomock.WithCommand("whoami"), gnomock.WithDebugMode())
if err != nil {
fmt.Printf("Error running container: %s", err)
}
But docker run busybox whoami
prints root
.
from gnomock.
Because docker run busybox
prints nothing, so there are no logs.
Try to debug your actual container using WithLogWriter
and see what it prints before exiting.
from gnomock.
Because
docker run busybox
prints nothing, so there are no logs. Try to debug your actual container usingWithLogWriter
and see what it prints before exiting.
I am sorry but docker run busybox whoami
prints root
for me. But I can also try it with the actual container but I expect the same (no log) result
from gnomock.
@Haegi did you have any luck with WithLogWriter
output of your real use case?
from gnomock.
Unfortunately, not. The container exits before the logging forwarding is even established.
It looks like the inspect in the waitForContainerNetwork is failing because the container is not there anymore. And I guess this triggers then the cleanup.
But maybe I am also missing something.
from gnomock.
The reason most likely is the AutoRemove
flag that we set on containers. They are deleted by docker when stopped. Containers that stop too quickly don't send their logs. I think the solution should be to not put this flag when WithDebugMode
flag is set, but I'm not sure what would be the consequences of it. If you want, you can make this change in your local fork and use it until you figure out the reason, because it will take some time for me to get to this issue.
from gnomock.
I just tried it out and you are right. With AutoRemove=false
the container is not removed and it can be inspected.
I would be open to contribute the change to not remove the container when WithDebugMode
is specified. But I am also not sure about the consequences and maybe it would be safer to introduce a new gnomock option (e.g. WithDisableAutoRemove
). What do you think?
from gnomock.
I would rather go with fixing the behaviour of WithDebugMode
. This options should not be used in stable builds, so this change should be safe. Would you like to open a pull request with this change?
Thanks.
from gnomock.
I would rather go with fixing the behaviour of
WithDebugMode
. This options should not be used in stable builds, so this change should be safe. Would you like to open a pull request with this change? Thanks.
Sure, I opened this PR for it: #757
from gnomock.
Related Issues (20)
- Feature: Configurable Docker Registry URL HOT 3
- It is safe NOT to call `gnomock.Stop()`? HOT 1
- Bug: gnomock-cleaner not work well in M1(arm64) HOT 4
- Bug: gnomockd in github action 'services:' & 'container:' requires preallocated exposed port range HOT 7
- Add a CI job that uses github service containers feature
- New preset: jaeger, tracing backend
- Bug: Healthcheck failed on running k3s preset example HOT 3
- Request: Custom the image of preset HOT 3
- Request: allow use of already previous test session Docker containers HOT 7
- New Option: Entrypoint HOT 1
- Bug: Remote certificate is expired - need to skip TLS verification HOT 1
- Bug: verifying module: checksum mismatch in dependecy HOT 3
- Bug: postgres WithDatabase() causes failure on WithContainerReuse() HOT 1
- Request: Include Timestream to localstack.Service HOT 1
- Bug: `WithUseLocalImagesFirst()` doesn't work with local only images HOT 2
- Bug: Healthcheck not working for docker in docker. HOT 7
- Request: Update go-elasticsearch to 8.7.0
- Bug: Container is broken HOT 6
- Request: Enable easily running containers in cluster mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gnomock.