[Yandex Cloud documentation](../../index.md) > [Yandex DataSphere](../index.md) > [Step-by-step guides](index.md) > Working with resources > Working with Docker images

# Working with Docker images

You can configure the environment for running your code using [Docker images](../concepts/docker.md).

Yandex DataSphere enables you to create repositories of Docker images and select an image to use in a project. The selected image will be used when running code in all project notebooks.

## Creating a Docker image {#create}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. In the top-right corner, click **Create resource**. In the pop-up window, select **Docker**.
1. Select the Docker image location:

   {% list tabs %}
   
   - Container Registry
   
     The image will be built in the [Yandex Container Registry](../../container-registry/index.md) registry. Running a project with an image from the registry depends on the image size and takes more time. You cannot [publish](#share) an image from the registry in the community.
   
     To build an image in Container Registry, the community administrator must specify the registry in [community settings](community/manage-community-config.md) and enable a [service agent](community/create-ssa.md).
   
     Fill out the fields as follows:

     * **Tag**: Image name and tag in `<name>:<tag>` format, e.g., `tensorflow:1.0.0`.
     * **Project storage mounting point**: Path to the directory whose contents you must have in the Docker image build context. The entire contents of this directory will take up space on the disk used to build your image. `.` is the root directory.
     * **Description**: Docker image description.
     * **Docker template**: Template with the minimum set of instructions you need to build a functional Docker image with the selected Python version.
     * **Docker file**: Instructions for creating a Docker image.

       Edit the contents of the field. For example, the following code will create a Docker image with `python_3_8` based on the original TensorFlow image:
 
       ```bash
       FROM tensorflow/tensorflow:2.7.0-gpu
 
       RUN set -e \
         && useradd -ms /bin/bash --uid 1000 jupyter \
         && pip install --no-cache-dir --upgrade pip \
         && pip install --no-cache-dir nptyping==1.4.4 pandas==1.4.1 opencv-python-headless==4.5.5.62 scikit-learn==1.0.2 \
         && ln -s /usr/bin/python3 /usr/local/bin/python3
       ```
   
   - DataSphere
   
     The Docker image will be built and optimized for DataSphere projects. You can [publish](#share) such a Docker image in the community. The resource will be placed in a dedicated storage you are going to [pay for](../pricing.md#storage) separately.

     Fill out the fields as follows:

     * **Disk size, GB**: Desired storage size in GB.
     * **Docker name**: Image name, e.g., `tensorflow`.
     * **Tag**: Image tag, e.g., `1.0.0`.
     * **Project storage mounting point**: Path to the project directory where the created Docker image will reside; `.` indicates the root directory.
     * **Description**: Docker image description.
     * **Docker template**: Template of the script to install Python.
     * **Docker file**: Instructions for creating a Docker image.

       Edit the contents of the field. For example, the following code will create a Docker image with `python_3_8` based on the original TensorFlow image:
 
       ```bash
       FROM tensorflow/tensorflow:2.7.0-gpu
 
       RUN set -e \
         && useradd -ms /bin/bash --uid 1000 jupyter \
         && pip install --no-cache-dir --upgrade pip \
         && pip install --no-cache-dir nptyping==1.4.4 pandas==1.4.1 opencv-python-headless==4.5.5.62 scikit-learn==1.0.2 \
         && ln -s /usr/bin/python3 /usr/local/bin/python3
       ```
   
   {% endlist %}

1. Optionally, activate **Authentication data** and specify your Docker Hub account username and password.

1. Click **Build**.

    This will create a Docker image with TensorFlow packages to enable GPU-based computations.

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, select ![docker](../../_assets/console-icons/logo-docker.svg) **Docker**.

{% note tip %}

The [Docker Hub](https://hub.docker.com/) image library has limits on anonymous usage. If you encounter slow or failed base image pulls when building a Docker image, try changing your project IP address. To do this:

* [Create a subnet](../../vpc/operations/subnet-create.md).
* [Create an egress NAT gateway](../../vpc/operations/create-nat-gateway.md).
* [Create a service account](../../iam/operations/sa/create.md) with the `vpc.user` role.
* In the [project settings](projects/update.md), add the subnet and the service account you created.

You can also use basic images from other libraries.

{% endnote %}

## Applying a Docker image to a project {#set}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, select ![docker](../../_assets/console-icons/logo-docker.svg) **Docker**.
1. Next to the image in question, click ![Options](../../_assets/console-icons/ellipsis.svg) and select ![Apply](../../_assets/console-icons/circle-check-fill.svg) **Activate**.
1. Open the project in JupyterLab and wait for it to load.
1. Open the notebook tab and make sure the custom image environment is available in your project. For example, for the TensorFlow image, create and run a cell with the following code:

    ```bash
    import tensorflow as tf
    tf.config.list_physical_devices('GPU')
    ```
1. Select the VM configuration. For example, to run a TensorFlow image, select a g1.1 GPU configuration. In the VM widget, the **Environment** field should give the full name of the image.

    Result:

    ```bash
    ...
    [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
    ```

To return to the default environment, follow these steps:
1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, select ![docker](../../_assets/console-icons/logo-docker.svg) **Docker**.
1. Next to the default image, click ![Options](../../_assets/console-icons/ellipsis.svg) and select ![Apply](../../_assets/console-icons/circle-check-fill.svg) **Activate**.

## Sharing a Docker image {#share}

A Docker image can be shared in the community only by the community administrator and only if the image is hosted in DataSphere.

To learn more about roles in DataSphere, see [Access management in DataSphere](../security/index.md).

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![docker](../../_assets/console-icons/logo-docker.svg) **Docker**.
1. Select the image from the list.
1. Go to the **Access** tab.
1. Enable the visibility option next to the name of the community you want to share the Docker image in.

To make a Docker image available for use in a different project, the project admin needs to [add](projects/use-shared-resource.md) that image on the **Shared** tab.

## Deleting a Docker image {#delete}

You cannot delete a Docker image if it is available for the entire community.

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![docker](../../_assets/console-icons/logo-docker.svg) **Docker**.
1. In the list of Docker images, select the one you want to delete.
1. Click ![options](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
1. Click **Confirm**.

You will see a message saying that the resource has been deleted.

{% note warning %}

In fact, [resource deletion](../../overview/concepts/data-deletion.md) can take up to 72 hours.

{% endnote %}