···715715```
716716:::
717717718718-## pullImage {#ssec-pkgs-dockerTools-fetchFromRegistry}
718718+[]{#ssec-pkgs-dockerTools-fetchFromRegistry}
719719+## pullImage {#ssec-pkgs-dockerTools-pullImage}
720720+721721+This function is similar to the `docker pull` command, which means it can be used to pull a Docker image from a registry that implements the [Docker Registry HTTP API V2](https://distribution.github.io/distribution/spec/api/).
722722+By default, the `docker.io` registry is used.
723723+724724+The image will be downloaded as an uncompressed Docker-compatible repository tarball, which is suitable for use with other `dockerTools` functions such as [`buildImage`](#ssec-pkgs-dockerTools-buildImage), [`buildLayeredImage`](#ssec-pkgs-dockerTools-buildLayeredImage), and [`streamLayeredImage`](#ssec-pkgs-dockerTools-streamLayeredImage).
725725+726726+This function requires two different types of hashes/digests to be specified:
727727+728728+- One of them is used to identify a unique image within the registry (see the documentation for the `imageDigest` attribute).
729729+- The other is used by Nix to ensure the contents of the output haven't changed (see the documentation for the `sha256` attribute).
730730+731731+Both hashes are required because they must uniquely identify some content in two completely different systems (the Docker registry and the Nix store), but their values will not be the same.
732732+See [](#ex-dockerTools-pullImage-nixprefetchdocker) for a tool that can help gather these values.
733733+734734+### Inputs {#ssec-pkgs-dockerTools-pullImage-inputs}
735735+736736+`pullImage` expects a single argument with the following attributes:
737737+738738+`imageName` (String)
719739720720-This function is analogous to the `docker pull` command, in that it can be used to pull a Docker image from a Docker registry. By default [Docker Hub](https://hub.docker.com/) is used to pull images.
740740+: Specifies the name of the image to be downloaded, as well as the registry endpoint.
741741+ By default, the `docker.io` registry is used.
742742+ To specify a different registry, prepend the endpoint to `imageName`, separated by a slash (`/`).
743743+ See [](#ex-dockerTools-pullImage-differentregistry) for how to do that.
744744+745745+`imageDigest` (String)
746746+747747+: Specifies the digest of the image to be downloaded.
748748+749749+ :::{.tip}
750750+ **Why can't I specify a tag to pull from, and have to use a digest instead?**
751751+752752+ Tags are often updated to point to different image contents.
753753+ The most common example is the `latest` tag, which is usually updated whenever a newer image version is available.
754754+755755+ An image tag isn't enough to guarantee the contents of an image won't change, but a digest guarantees this.
756756+ Providing a digest helps ensure that you will still be able to build the same Nix code and get the same output even if newer versions of an image are released.
757757+ :::
758758+759759+`sha256` (String)
760760+761761+: The hash of the image after it is downloaded.
762762+ Internally, this is passed to the [`outputHash`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-outputHash) attribute of the resulting derivation.
763763+ This is needed to provide a guarantee to Nix that the contents of the image haven't changed, because Nix doesn't support the value in `imageDigest`.
721764722722-Its parameters are described in the example below:
765765+`finalImageName` (String; _optional_)
723766724724-```nix
725725-pullImage {
726726- imageName = "nixos/nix";
727727- imageDigest =
728728- "sha256:473a2b527958665554806aea24d0131bacec46d23af09fef4598eeab331850fa";
729729- finalImageName = "nix";
730730- finalImageTag = "2.11.1";
731731- sha256 = "sha256-qvhj+Hlmviz+KEBVmsyPIzTB3QlVAFzwAY1zDPIBGxc=";
732732- os = "linux";
733733- arch = "x86_64";
734734-}
735735-```
767767+: Specifies the name that will be used for the image after it has been downloaded.
768768+ This only applies after the image is downloaded, and is not used to identify the image to be downloaded in the registry.
769769+ Use `imageName` for that instead.
736770737737-- `imageName` specifies the name of the image to be downloaded, which can also include the registry namespace (e.g. `nixos`). This argument is required.
771771+ _Default value:_ the same value specified in `imageName`.
738772739739-- `imageDigest` specifies the digest of the image to be downloaded. This argument is required.
773773+`finalImageTag` (String; _optional_)
740774741741-- `finalImageName`, if specified, this is the name of the image to be created. Note it is never used to fetch the image since we prefer to rely on the immutable digest ID. By default it's equal to `imageName`.
775775+: Specifies the tag that will be used for the image after it has been downloaded.
776776+ This only applies after the image is downloaded, and is not used to identify the image to be downloaded in the registry.
742777743743-- `finalImageTag`, if specified, this is the tag of the image to be created. Note it is never used to fetch the image since we prefer to rely on the immutable digest ID. By default it's `latest`.
778778+ _Default value:_ `"latest"`.
744779745745-- `sha256` is the checksum of the whole fetched image. This argument is required.
780780+`os` (String; _optional_)
746781747747-- `os`, if specified, is the operating system of the fetched image. By default it's `linux`.
782782+: Specifies the operating system of the image to pull.
783783+ If specified, its value should follow the [OCI Image Configuration Specification](https://github.com/opencontainers/image-spec/blob/main/config.md#properties), which should still be compatible with Docker.
784784+ According to the linked specification, all possible values for `$GOOS` in [the Go docs](https://go.dev/doc/install/source#environment) should be valid, but will commonly be one of `darwin` or `linux`.
748785749749-- `arch`, if specified, is the cpu architecture of the fetched image. By default it's `x86_64`.
786786+ _Default value:_ `"linux"`.
750787751751-`nix-prefetch-docker` command can be used to get required image parameters:
788788+`arch` (String; _optional_)
752789753753-```ShellSession
754754-$ nix run nixpkgs#nix-prefetch-docker -- --image-name mysql --image-tag 5
790790+: Specifies the architecture of the image to pull.
791791+ If specified, its value should follow the [OCI Image Configuration Specification](https://github.com/opencontainers/image-spec/blob/main/config.md#properties), which should still be compatible with Docker.
792792+ According to the linked specification, all possible values for `$GOARCH` in [the Go docs](https://go.dev/doc/install/source#environment) should be valid, but will commonly be one of `386`, `amd64`, `arm`, or `arm64`.
793793+794794+ _Default value:_ the same value from `pkgs.go.GOARCH`.
795795+796796+`tlsVerify` (Boolean; _optional_)
797797+798798+: Used to enable or disable HTTPS and TLS certificate verification when communicating with the chosen Docker registry.
799799+ Setting this to `false` will make `pullImage` connect to the registry through HTTP.
800800+801801+ _Default value:_ `true`.
802802+803803+`name` (String; _optional_)
804804+805805+: The name used for the output in the Nix store path.
806806+807807+ _Default value:_ a value derived from `finalImageName` and `finalImageTag`, with some symbols replaced.
808808+ It is recommended to treat the default as an opaque value.
809809+810810+### Examples {#ssec-pkgs-dockerTools-pullImage-examples}
811811+812812+::: {.example #ex-dockerTools-pullImage-niximage}
813813+# Pulling the nixos/nix Docker image from the default registry
814814+815815+This example pulls the [`nixos/nix` image](https://hub.docker.com/r/nixos/nix) and saves it in the Nix store.
816816+817817+```nix
818818+{ dockerTools }:
819819+dockerTools.pullImage {
820820+ imageName = "nixos/nix";
821821+ imageDigest = "sha256:b8ea88f763f33dfda2317b55eeda3b1a4006692ee29e60ee54ccf6d07348c598";
822822+ finalImageName = "nix";
823823+ finalImageTag = "2.19.3";
824824+ sha256 = "zRwlQs1FiKrvHPaf8vWOR/Tlp1C5eLn1d9pE4BZg3oA=";
825825+}
755826```
827827+:::
756828757757-Since a given `imageName` may transparently refer to a manifest list of images which support multiple architectures and/or operating systems, you can supply the `--os` and `--arch` arguments to specify exactly which image you want. By default it will match the OS and architecture of the host the command is run on.
829829+::: {.example #ex-dockerTools-pullImage-differentregistry}
830830+# Pulling the nixos/nix Docker image from a specific registry
831831+832832+This example pulls the [`coreos/etcd` image](https://quay.io/repository/coreos/etcd) from the `quay.io` registry.
833833+834834+```nix
835835+{ dockerTools }:
836836+dockerTools.pullImage {
837837+ imageName = "quay.io/coreos/etcd";
838838+ imageDigest = "sha256:24a23053f29266fb2731ebea27f915bb0fb2ae1ea87d42d890fe4e44f2e27c5d";
839839+ finalImageName = "etcd";
840840+ finalImageTag = "v3.5.11";
841841+ sha256 = "Myw+85f2/EVRyMB3axECdmQ5eh9p1q77FWYKy8YpRWU=";
842842+}
843843+```
844844+:::
845845+846846+::: {.example #ex-dockerTools-pullImage-nixprefetchdocker}
847847+# Finding the digest and hash values to use for `dockerTools.pullImage`
758848759759-```ShellSession
760760-$ nix-prefetch-docker --image-name mysql --image-tag 5 --arch x86_64 --os linux
849849+Since [`dockerTools.pullImage`](#ssec-pkgs-dockerTools-pullImage) requires two different hashes, one can run the `nix-prefetch-docker` tool to find out the values for the hashes.
850850+The tool outputs some text for an attribute set which you can pass directly to `pullImage`.
851851+852852+```shell
853853+$ nix run nixpkgs#nix-prefetch-docker -- --image-name nixos/nix --image-tag 2.19.3 --arch amd64 --os linux
854854+(some output removed for clarity)
855855+Writing manifest to image destination
856856+-> ImageName: nixos/nix
857857+-> ImageDigest: sha256:498fa2d7f2b5cb3891a4edf20f3a8f8496e70865099ba72540494cd3e2942634
858858+-> FinalImageName: nixos/nix
859859+-> FinalImageTag: latest
860860+-> ImagePath: /nix/store/4mxy9mn6978zkvlc670g5703nijsqc95-docker-image-nixos-nix-latest.tar
861861+-> ImageHash: 1q6cf2pdrasa34zz0jw7pbs6lvv52rq2aibgxccbwcagwkg2qj1q
862862+{
863863+ imageName = "nixos/nix";
864864+ imageDigest = "sha256:498fa2d7f2b5cb3891a4edf20f3a8f8496e70865099ba72540494cd3e2942634";
865865+ sha256 = "1q6cf2pdrasa34zz0jw7pbs6lvv52rq2aibgxccbwcagwkg2qj1q";
866866+ finalImageName = "nixos/nix";
867867+ finalImageTag = "latest";
868868+}
761869```
762870763763-Desired image name and tag can be set using `--final-image-name` and `--final-image-tag` arguments:
871871+It is important to supply the `--arch` and `--os` arguments to `nix-prefetch-docker` to filter to a single image, in case there are multiple architectures and/or operating systems supported by the image name and tags specified.
872872+By default, `nix-prefetch-docker` will set `os` to `linux` and `arch` to `amd64`.
764873765765-```ShellSession
766766-$ nix-prefetch-docker --image-name mysql --image-tag 5 --final-image-name eu.gcr.io/my-project/mysql --final-image-tag prod
874874+Run `nix-prefetch-docker --help` for a list of all supported arguments:
875875+```shell
876876+$ nix run nixpkgs#nix-prefetch-docker -- --help
877877+(output removed for clarity)
767878```
879879+:::
768880769881## exportImage {#ssec-pkgs-dockerTools-exportImage}
770882