Docker is a tool to build, deploy, and run applications using containers.
Docker images and containers can be deployed to many different platforms, like AWS, Azure, and Google Cloud. This recipe won’t cover how to deploy your site to a specific platform but will show you how to set up Docker for your project.
Create a file called Dockerfile
in your project’s root directory. This file contains the instructions to build your site, which will differ depending on your needs. This guide can’t show all possible options but will give you starting points for SSR and static mode.
This Dockerfile will build your site and serve it using Node.js on port 3000
and therefore requires the Node adapter installed in your Astro project.
The following Dockerfile will build your site and serve it using Apache htppd on port 80
with the default configuration.
In order to build the Dockerfile above, you’ll also need to create a configuration file for NGINX. Create a folder called nginx
in your project’s root directory and create a file called nginx.conf
inside.
<your-astro-image-name>
:This will output an image, which you can run locally or deploy to a platform of your choice.
Replace <local-port>
with an open port on your machine. Replace <container-port>
with the port exposed by your Docker container (3000
, 80
, or 8080
in the above examples.)
You should be able to access your site at http://localhost:<local-port>
.
Learn how to share state across framework components with Nano Stores.
Add an RSS feed to your Astro site to let users subscribe to your content.
Learn how you can import YAML data by adding a Rollup plugin to your project.
Learn how to use JavaScript to send form submissions to an API Route
Learn how to build HTML forms and handle submissions in your frontmatter
Learn how to use Bun with your Astro site.
Learn how to call endpoints from the server in Astro.
Learn how to create an API route and fetch it from the client.
Learn how to build your Astro site using Docker.
Learn how to install a rehype plugin to add icons to external links in your Markdown files
Use dynamic routing and content collections to add internationalization support to your Astro site.
Build a remark plugin to add reading time to your Markdown or MDX files.
Learn how to share state across Astro components with Nano Stores.
© 2021 Fred K. Schott
Licensed under the MIT License.
https://docs.astro.build/en/recipes/docker/