Skip to content

Commit 4bacf4b

Browse files
author
Christer Barreholm
committed
cmd line arg --network to create shared network for sidecar
1 parent 6ac8624 commit 4bacf4b

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,22 @@ claude-podman \
5353
--apk-packages kubectl \
5454
--podman-arg "-v $HOME/.kube/config:/home/claude/.kube/config"
5555
```
56+
57+
Sharing a network with another container
58+
----
59+
60+
By default the container uses podman's rootless network and can't reach other
61+
containers by name. Use `--network NAME` to join a dedicated, user-defined
62+
podman network (it's created automatically if it doesn't exist). Any other
63+
container on the same network is then reachable from inside by its container
64+
name, thanks to podman's built-in DNS.
65+
66+
```sh
67+
# Start the service Claude should reach, on a shared network
68+
podman run -d --name myservice --network claude-net some/image
69+
70+
# Run Claude on the same network (creates claude-net if needed)
71+
claude-podman --network claude-net
72+
```
73+
74+
Inside the container, Claude can now reach the service at `http://myservice:<port>`.

bin/claude

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ NAME="claudecode-$(uuidgen -r | cut -d- -f1)"
88
INIT_SCRIPT=""
99
APK_PACKAGES=""
1010
PODMAN_ARGS=""
11+
NETWORK=""
1112

1213
# Process arguments
1314
while [[ $# -gt 0 ]]; do
@@ -22,6 +23,8 @@ while [[ $# -gt 0 ]]; do
2223
--local Use local image 'claude-code:latest' instead of remote
2324
--init-script FILE Execute initialization script
2425
--apk-packages LIST Install additional Alpine packages (comma or space separated)
26+
--network NAME Join a dedicated podman network (created if missing) so
27+
Claude can reach other containers on it by name via DNS
2528
--podman-arg ARG Pass additional argument to podman
2629
--version Show the Claude Code version in the image
2730
--help Display this help message
@@ -49,6 +52,10 @@ while [[ $# -gt 0 ]]; do
4952
APK_PACKAGES="$2"
5053
shift 2
5154
;;
55+
--network)
56+
NETWORK="$2"
57+
shift 2
58+
;;
5259
--podman-arg)
5360
PODMAN_ARGS="$PODMAN_ARGS $2"
5461
shift 2
@@ -68,6 +75,15 @@ while [[ $# -gt 0 ]]; do
6875
esac
6976
done
7077

78+
# Join a dedicated network, creating it if it doesn't exist yet
79+
NETWORK_ARG=""
80+
if [ -n "$NETWORK" ]; then
81+
if ! podman network exists "$NETWORK"; then
82+
podman network create "$NETWORK"
83+
fi
84+
NETWORK_ARG="--network $NETWORK"
85+
fi
86+
7187
podman run \
7288
-v "${HOME}/.claude:/home/claude/.claude" \
7389
-v "${HOME}/.claude.json:/home/claude/.claude.json" \
@@ -79,6 +95,7 @@ podman run \
7995
--detach \
8096
--user claude \
8197
--userns=keep-id:uid=1000,gid=1000 \
98+
$NETWORK_ARG \
8299
$PODMAN_ARGS \
83100
"$IMAGE" "$@"
84101

0 commit comments

Comments
 (0)