Build from a Dockerfile
We will look for and use a Dockerfile
at the service's root if it exists.
CloudStation notifies you when it's using the Dockerfile
in the build process with the following message in the logs:
==========================
Using detected Dockerfile!
==========================
Custom Dockerfile Path
By default, we look for a file named Dockerfile
in the root directory. If you want to use a custom filename or path, you can set a variable defining the path.
In your service variables, set a variable named CLOUDSTATION_DOCKERFILE_PATH
to specify the path to the file.
For example, if your Dockerfile was called Dockerfile.origin
, you would specify it like this:
CLOUDSTATION_DOCKERFILE_PATH=Dockerfile.origin
If your Dockerfile is in another directory, specify it like this:
CLOUDSTATION_DOCKERFILE_PATH=/build/Dockerfile
Use Config as Code
You can also set your custom Dockerfile path using config as code.
Using Variables at Build Time
If you need to use the environment variables that CloudStation injects at build time, which include variables that you define and CloudStation-shared variables, you must specify them in the Dockerfile using the ARG
command.
For example:
# Specify the variable you need
ARG CLOUDSTATION_SERVICE_NAME
# Use the variable
RUN echo $CLOUDSTATION_SERVICE_NAME
Be sure to declare your environment variables in the stage they are required in:
FROM node
ARG CLOUDSTATION_ENVIRONMENT
Cache Mounts
CloudStation supports cache mounts in your Dockerfile in the following format:
--mount=type=cache,id=s/<service id>-<target path>,target=<target path>
Replace <service id>
with the id of the service.
Target Path
Unsure of what your target path should be? Refer to the Nixpacks source code. Within the providers directory, find the file that aligns with your respective language or runtime, and check for the variable that indicates the CACHE_DIR.
Docker Compose
You can import services straight from your Docker Compose file! Just drag and drop your Compose file onto your project, and your services (and any mounted volumes) will be auto-imported as staged changes. It’s like magic, but with YAML instead of wands. 🪄
A quick heads-up: we don’t support every possible Compose config just yet (because Rome wasn’t built in a day). But don’t worry, we’re on it!
Docker Configuration
This section provides detailed information on how to configure Docker for your projects.
Introduction
Docker is a powerful tool for containerizing applications. This guide will walk you through the steps to configure Docker for your project.
Steps
- Install Docker: Follow the official Docker installation guide to install Docker on your system.
- Create a Dockerfile: A Dockerfile is a text document that contains all the commands to assemble an image. Here is an example:
FROM node:14 WORKDIR /app COPY . . RUN npm install CMD ["node", "index.js"]
- Build the Docker Image: Use the following command to build your Docker image:
docker build -t my-app .
- Run the Docker Container: Use the following command to run your Docker container:
docker run -p 3000:3000 my-app
Custom Dockerfile Path
By default, Docker looks for a file named Dockerfile
in the root directory. If you want to use a custom filename or path, you can specify it using the -f
option:
docker build -t my-app -f path/to/Dockerfile .
Using Environment Variables
If you need to use environment variables during the build process, you can specify them in the Dockerfile using the ARG
command:
# Specify the variable you need
ARG MY_VARIABLE
# Use the variable
RUN echo $MY_VARIABLE
Conclusion
By following these steps, you can configure Docker for your project and take advantage of containerization to streamline your development and deployment processes.
Edit this file on GitHub