Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing options to Docker::Image.create #33

Merged

Conversation

HeyNonster
Copy link
Contributor

@HeyNonster HeyNonster commented Dec 14, 2023

The Docker ImageCreate api accepts a variety of parameters, you can pass those arguments in a hash as the first argument to Docker:Image.create

For the platform behavior, there is default behavior which is notable:

Default: ""

When used in combination with the fromImage option, the daemon checks if the given image is present
in the local image cache with the given OS and Architecture, and otherwise attempts to pull the image. 
If the option is not set, the host's native OS and Architecture are used.
...

Because it defauilts to the host's native architecture, it will attempt to pull images matching that architecture and raises not found if an image of that architecture doesn't exist. This can be a problem when, for example, attempting to pull a mysql image on Mx Macs. Testcontainers::DockerContainer.create('mysql:5.7') will fail because, as of this writing, arm images are not created for mysql:5.7.

The solution to this is to pass platform: 'linux/amd64' to Docker::Image.create. This tells Docker we specifically want a image for that architecture (Rosetta on Mac OS X can run linux/amd64 images).

This commit adds an optional image_create_options kwarg to DockerContainer#initialize that defaults to an empty hash. This kwarg allows for us to pass create parameters to Docker::Image.create.

I've also added a NotFoundError class because it seems that the convention is to wrap dependency errors in a Textcontainers error class.

Updates the readme, including a readme addition to explain the changes in #31.

The [Docker ImageCreate](https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageCreate)
api accepts a variety of parameters.

For the `platform` behavior, there is default behavior which is notable:

```
Default: ""

When used in combination with the fromImage option, the daemon checks if the given image is present in the local image cache with the given OS and Architecture, and otherwise attempts to pull the image. If the option is not set, the host's native OS and Architecture are used.
...
```

Because it defauilts to the host's native architecture, it will attempt
to pull images matching that architecture and raises not found if an
image of that architecture doesn't exist. This can be a problem when,
for example, attempting to pull a `mysql` image on Mx Macs.
`Testcontainers::DockerContainer.create('mysql:5.7')` will fail because,
as of this writing, arm images are not created for `mysql:5.7`.

The solution to this is to pass `platform: 'linux/amd64'` to
`Docker::Image.create`. This tells Docker we specifically want a image
for that architecture (Rosetta on Mac OS X can run `linux/amd64` images).

This commit adds an optional `image_create_options` kwarg to
`DockerContainer#initialize` that defaults to an empty hash. This kwarg
allows for us to pass create parameters to `Docker::Image.create`.

I've also added a `NotFoundError` class because it seems that the
convention is to wrap dependency errors in a `Textcontainers` error class.

Updates the readme, including a readme addition to explain the changes
in testcontainers#31.
@HeyNonster HeyNonster force-pushed the nony--container-create-options branch from f171a70 to 9f09d43 Compare December 14, 2023 14:02
@HeyNonster HeyNonster marked this pull request as ready for review December 14, 2023 14:09
@HeyNonster
Copy link
Contributor Author

MySQL module failure should be solved by #32.

The Redpanda tests failure seems unrelated?

@guilleiguaran guilleiguaran merged commit a2217ba into testcontainers:main Dec 16, 2023
17 of 19 checks passed
@guilleiguaran
Copy link
Member

@HeyNonster thanks, I need to check the Redpanda tests since those fail from time to time

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.

2 participants