What's the problem?
I have recently started running R, RStudio and Quarto from Docker containers. Easy deployment, but a bit of a pain to fit into my current workflow where I write a paper as a Quarto document in VS Code and preview its output using Quarto. Quarto expects to be installed on your local machine, so you can only preview quarto preview article.qmd
from within the Docker container. This is a use case the VS Code extension does not expect and therefore does not support. Boo!
The solution
I have created a forwarder for Quarto and Docker, for the following, rather niche use case:
- you use VS Code on your local machine
- you use the official Quarto extension for VS Code
- you would like to have Quarto and R (or Python, for what it's worth) installed inside a Docker container
- you want to preview your Quarto document using the Quarto installation inside the Docker container
The forwarder pretends to be the Quarto binary, but instead forwards the call to Quarto to the Quarto binary inside the Docker container. I wish it worked automagically and all that, but I only have so much time so some manual set-up is required.
How to use
- Download the
quarto
script from this GitHub repository - Change
DOCKER_CONTAINER_NAME
to the name of the container where Quarto is installed
ChangeQMD_DOCKER_PATH
to the path of your Quarto document inside the container - Set execution rights to your
quarto
script:chmod +x quarto
- Make sure to forward port 8788 inside your
docker-compose
file (or however you are running your Docker container) - You can now press CTRL ^ SHIFT ^ K and have your
quarto preview
request be forwarded to your Docker container.
The script I made has comments which explain what each command does. Hope this helps! May your articles be accepted :-).