Skip to content

Commit

Permalink
Update guestbook/localdb/main.go to add docker platform flag
Browse files Browse the repository at this point in the history
Code didn't run on my m1 macbook pro, getting
```
$ go run localdb/main.go
go: downloading gopkg.in/pipe.v2 v2.0.0-20140414041502-3c2ca4d52544
localdb: Starting container running MySQL
Unable to find image 'mysql:5.6' locally
docker: Error response from daemon: no match for platform in manifest: not found.
See 'docker run --help'.
localdb: running [docker run --rm --env MYSQL_DATABASE=guestbook --env MYSQL_ROOT_PASSWORD=password --detach --publish 3306:3306 mysql:5.6]: exit status 125:
exit status 1
```

That's because mysql:5.6 only had a linux/amd64 image (https://hub.docker.com/layers/library/mysql/5.6/images/sha256-897086d07d1efa876224b147397ea8d3147e61dd84dce963aace1d5e9dc2802d?context=explore). Adding the platform flag tells docker to download it anyways, even on a mac. 

I always use this trick but honestly not sure why amd64 images run on m1 chips. Maybe there's no meaningful difference? Maybe its because of Rosetta? Or maybe I'll eventually hit a bug because some features are not available when running on different arch?
  • Loading branch information
samlaf authored Jul 13, 2024
1 parent 0a37d2f commit 4cfae61
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions samples/guestbook/localdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func runLocalDB(containerName, guestbookDir string) error {
dockerArgs = append(dockerArgs, "--name", containerName)
}
dockerArgs = append(dockerArgs,
"--platform", "linux/amd64",

Check warning on line 56 in samples/guestbook/localdb/main.go

View check run for this annotation

Codecov / codecov/patch

samples/guestbook/localdb/main.go#L56

Added line #L56 was not covered by tests
"--env", "MYSQL_DATABASE=guestbook",
"--env", "MYSQL_ROOT_PASSWORD=password",
"--detach",
Expand Down

0 comments on commit 4cfae61

Please sign in to comment.