# Running Stable Diffusion in Docker

## Getting Started

Begin by registering for TensorDock Marketplace and selecting a GPU with at least 10 GB of memory to launch an instance.&#x20;

<figure><img src="https://276866638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FScYFYZoiZXazILi6lxJ5%2Fuploads%2FKJKzHnHepVpZb1bCgwI9%2Fimage.png?alt=media&#x26;token=e98ab845-4643-47db-9a35-f423b62652b9" alt=""><figcaption></figcaption></figure>

We will be using a Ubuntu instance for this tutorial. Select an external port that maps to the internal port 22. This will allowing SSHing into the instance.

<figure><img src="https://276866638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FScYFYZoiZXazILi6lxJ5%2Fuploads%2FDaDFcUqMYK8YvllxY8eB%2Fimage.png?alt=media&#x26;token=96bd6ea0-ff25-46af-893b-8f8687f33d27" alt=""><figcaption></figcaption></figure>

Finish up your server by setting a secure username and password.

## SSH into the server

On the information page for your instance, you can find the necessary IPv4 address and command to SSH through the command line.

<figure><img src="https://276866638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FScYFYZoiZXazILi6lxJ5%2Fuploads%2FgUmDRGe7czMiwyC697Ir%2Fimage.png?alt=media&#x26;token=824303c1-2c7c-4d60-877e-9c25445da3a6" alt=""><figcaption></figcaption></figure>

Using the command, you can SSH into your server. Through command line, you will need to enter your username and password which will then grant you access to the GPU and using it for stable diffusion!

## Using Docker and Docker Networking

Docker comes default in all TensorDock instances, however by adding Docker Networking, you can make external requests needed for stable diffusion. First, clone the following git repo and cd into that directory.

`git clone https://github.com/monatis/stable-diffusion-tf-docker.git && cd stable-diffusion-tf-docker`

Then, we will add the `daemon.json` file and restart the docker service.

`sudo cp ./daemon.json /etc/docker/daemon.json`

`sudo systemctl restart docker.service`

### Setting up Docker Compose

With Docker Compose, we can create a `docker-compose.yml` file that will look to a specified port variable for the GPU. On whatever external port you chose to forward to port 22, run

&#x20;`export PUBLIC_PORT= *your port number here*`

`docker compose up -d`

Once it’s up and running, go to `http://mass-a.tensordockmarketplace.com:*port number*/docs` for the Swagger UI provided by FastAPI. Using the `POST /generate` endpoint, you can generate your image and its download id. You can download it with GET `/download/<download_id>` .
