[GH-ISSUE #1952] Access from inside docker network and externally #231

Open
opened 2026-03-03 12:09:19 +03:00 by kerem · 1 comment
Owner

Originally created by @glenn-smith-0 on GitHub (Apr 9, 2025).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1952

Hey, we have been using this emulator and been really happy with it so far. We have encountered an issue that we hope can be resolved, it's most likely a misconfiguration on our side but would appreciate some advice.

We have a go app that accesses a bucket in gcs to download resources. We want to replicate this in our local env. Currently we are able to do this within docker compose (both the go service and the fake-gcs-server in the same network, along with other services).

We would like to be able to keep this working but also have the go service be able to be run independently of the docker network and still be able to access the fake-gcs-server, to enable work on the go service independently without having to start it in the docker network each time.

this is our current compose file set up

  gcp-gcs:
    container_name: gcp-gcs
    image: fsouza/fake-gcs-server:1.52
    ports:
      - "4443:4443"
    volumes:
      - ${PWD}/buckets/data:/data
    command: [
      "-scheme", "http",
      "-public-host", "gcp-gcs:4443"
    ]

  my_service:
    build: ../my_service
    container_name: my_service
    image: my_service:latest
    ports:
      - "5555:5555"

here is a simplified snippet of the code to show the values were are using when running externally

the main difference being within docker network it works using

option.WithEndpoint("http://gcp-gcs:4443/storage/v1/")
func run() {
	bucket := "my_bucket"
	client, err := storage.NewClient(context.TODO(), option.WithEndpoint("http://localhost:4443/storage/v1/"), option.WithoutAuthentication())
	if err != nil {
		log.Fatalf("failed to create client: %v", err)
	}
	ctx := context.Background()

	// list objects in bucket
	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
	defer cancel()

	it := client.Bucket(bucket).Objects(ctx, nil)
	for {
		attrs, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			log.Fatalf("bucket(%q).Objects: %v", bucket, err)
		}
		fmt.Println(attrs.Name)
	}

	// get object from bucket
	r, err := client.Bucket(bucket).Object("tester.txt").NewReader(ctx)
	if err != nil {
		log.Fatalf("failed to create reader: %v", err)
	}

	defer r.Close()

	b, err := io.ReadAll(r)
	if err != nil {
		log.Fatalf("failed to read object: %v", err)
	}

	fmt.Println("content", string(b))
}

we have preloaded a file tester.txt in bucket my_bucket', I can see it when we list the bucket content, but when i attempt to download, the error is failed to create reader: storage: object doesn't exist`

Is there some config i can do to preserve the behaviour of downloads from within docker working whilst allowing downloads from an app running external to the network?

Thanks

Originally created by @glenn-smith-0 on GitHub (Apr 9, 2025). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1952 Hey, we have been using this emulator and been really happy with it so far. We have encountered an issue that we hope can be resolved, it's most likely a misconfiguration on our side but would appreciate some advice. We have a go app that accesses a bucket in gcs to download resources. We want to replicate this in our local env. Currently we are able to do this within docker compose (both the go service and the fake-gcs-server in the same network, along with other services). We would like to be able to keep this working but also have the go service be able to be run independently of the docker network and still be able to access the fake-gcs-server, to enable work on the go service independently without having to start it in the docker network each time. this is our current compose file set up ``` gcp-gcs: container_name: gcp-gcs image: fsouza/fake-gcs-server:1.52 ports: - "4443:4443" volumes: - ${PWD}/buckets/data:/data command: [ "-scheme", "http", "-public-host", "gcp-gcs:4443" ] my_service: build: ../my_service container_name: my_service image: my_service:latest ports: - "5555:5555" ``` here is a simplified snippet of the code to show the values were are using when running externally the main difference being within docker network it works using ```go option.WithEndpoint("http://gcp-gcs:4443/storage/v1/") ``` ```go func run() { bucket := "my_bucket" client, err := storage.NewClient(context.TODO(), option.WithEndpoint("http://localhost:4443/storage/v1/"), option.WithoutAuthentication()) if err != nil { log.Fatalf("failed to create client: %v", err) } ctx := context.Background() // list objects in bucket ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() it := client.Bucket(bucket).Objects(ctx, nil) for { attrs, err := it.Next() if err == iterator.Done { break } if err != nil { log.Fatalf("bucket(%q).Objects: %v", bucket, err) } fmt.Println(attrs.Name) } // get object from bucket r, err := client.Bucket(bucket).Object("tester.txt").NewReader(ctx) if err != nil { log.Fatalf("failed to create reader: %v", err) } defer r.Close() b, err := io.ReadAll(r) if err != nil { log.Fatalf("failed to read object: %v", err) } fmt.Println("content", string(b)) } ``` we have preloaded a file tester.txt in bucket `my_bucket', I can see it when we list the bucket content, but when i attempt to download, the error is `failed to create reader: storage: object doesn't exist` Is there some config i can do to preserve the behaviour of downloads from within docker working whilst allowing downloads from an app running external to the network? Thanks
Author
Owner

@glenn-smith-0 commented on GitHub (Apr 9, 2025):

Just discovered that doing this resolved my issue

<!-- gh-comment-id:2790220993 --> @glenn-smith-0 commented on GitHub (Apr 9, 2025): Just discovered that doing [this](https://github.com/fsouza/fake-gcs-server/issues/1202#issuecomment-1644877525) resolved my issue
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#231
No description provided.