> For the complete documentation index, see [llms.txt](https://hmdc.gitbook.io/r/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hmdc.gitbook.io/r/deploy/developlocallywithdocker.md).

# Developing locally using Docker

Using Docker to run your R Shiny app locally will produce a running instance of your application which mirrors Heroku 1:1. While testing your application within RStudio should work in most cases, running your application with Docker can provide additional verification for any code changes you've made.

Haven't yet installed Docker? Read [Setup your environment](/r/deploy/setupenvironment.md) before continuing.

All the following exercises use [heroku-docker-r-example-app](https://github.com/hmdc/heroku-docker-r-example-app) as the example application. To test your own application, substitute `heroku-docker-r-example-app` with your own application checkout or directory.

## Building your application docker image

The following command will compile your application into a docker image tagged with the name *my-local-heroku-docker-r-example-app*. You will see the same build output as you would if you pushed your code to the git Heroku remote.

```
cd heroku-docker-r-example-app
docker build -t my-local-heroku-docker-r-example-app .
```

## Running your application docker image

Once completed, you can run the docker image you produced:

```bash
docker run -p 8080:8080 -e PORT=8080 my-local-heroku-docker-r-example-app:latest
```

This will run your Shiny application on port 8080. You may need to click *Allow* on any security-related popups, common to Windows and Mac OS X, which ask whether you want to allow Docker to bind to port 8080.

If you're already using port 8080 or want to use a different port, substitute 8080 throughout the entire command with a different port number, except for ports 12000 to 13000 which are reserved for R threads within the container.

```bash
docker run -p 11000:11000 -e PORT=11000 my-local-heroku-docker-r-example-app:latest
```

## Viewing in the browser

Go to <http://localhost:8080> and you should see your application.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hmdc.gitbook.io/r/deploy/developlocallywithdocker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
