Skip to content

Attach to externally-started LS container#190

Draft
carole-lavillonniere wants to merge 5 commits intootel-tracingfrom
attach-to-running
Draft

Attach to externally-started LS container#190
carole-lavillonniere wants to merge 5 commits intootel-tracingfrom
attach-to-running

Conversation

@carole-lavillonniere
Copy link
Copy Markdown
Collaborator

@carole-lavillonniere carole-lavillonniere commented Apr 14, 2026

Summary

  • lstk start now attaches to an already-running LocalStack container instead of failing — warns if the running version differs from config, exits 0 in both cases
  • lstk stop gains the same fallback: locates and stops externally-started containers

Towards DRG-553

Started outside of lstk (eg CLI v1, or locally built and ran in docker):

running-with-clliv1

Already running but with another version:

running-other-version

Status command shows details about the version and container name:

running-local-build

Possible improvement:

Add interactivity and let user decide if the existing container should be picked up or replaced

When `lstk start` is run and a LocalStack container is already running
(started outside lstk, e.g. via docker run or Compose), lstk now attaches
to it rather than failing or trying to start a duplicate.

Detection uses two complementary strategies:
- Docker API: `FindRunningByImage` filters by image repo + bound host port
  via the `ancestor` filter, returning the running container regardless of
  its name or tag
- HTTP fallback: if the Docker filter misses it (different image name,
  mid-restart), `/_localstack/info` is probed on the configured port

Behaviour on attach:
- Same version as config: "LocalStack is already running" (exit 0)
- Different version: warning with both versions shown (exit 0)
- Port in use by non-LocalStack process: existing error (exit 1)

`lstk stop` also gains the same fallback: if no container matches the
configured name, `FindRunningByImage` is used to locate and stop the
externally-started container. `ContainerRemove` conflict/not-found errors
(e.g. container started with --rm) are now silently ignored since removal
was already in progress.
- start: attach to container started outside lstk (by image prefix + port),
  warn on version mismatch, skip pull/start
- stop: find and stop external containers via FindRunningByImage fallback
- status: same resolveRunningContainerName fallback so external containers
  are reflected correctly
- docker: fix FindRunningByImage to match by image string prefix instead of
  Docker ancestor filter (which fails when untagged image isn't locally pulled)
- integration tests: TestStartCommandAttachesExternalContainer,
  TestStopCommandStopsExternalContainer using tagged alpine as fake image
Logout's "LocalStack is still running" hint now detects containers
started outside lstk, consistent with stop and status.
@carole-lavillonniere carole-lavillonniere changed the title feat: attach to externally-started LocalStack containers Attach to externally-started LS container Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant