Learn how to seamlessly integrate Bolt.new AI with Docker using step-by-step instructions and best practices to optimize your containerized AI workflow.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
server.ts
) in your Bolt.new AI project.server.ts
. This code sets up an Express server that listens on a configurable port using the environment variable PORT
(which Docker can set) or defaults to 3000:
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello from Bolt.new AI integrated with Docker!');
});
app.listen(port, '0.0.0.0', () => {
console.log(Server is running on port ${port});
});
dist
directory) using the TypeScript compiler (tsc
).
Dockerfile
.Dockerfile
. This file tells Docker how to build your application’s image:
Use an official Node.js runtime as a parent image
FROM node:18-alpine
Set the working directory in the container
WORKDIR /app
Copy package.json and package-lock.json (if available)
COPY package*.json ./
Install dependencies
RUN npm install
Copy the rest of your application's source code
COPY . .
If you have a build step, uncomment the following line:
RUN npm run build
Expose the port on which your app will run
EXPOSE 3000
Define the command to run your app
CMD ["npm", "start"]
package.json
file (or create one if it doesn’t exist) in the root of your project.
{
"name": "bolt-ai-docker",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"build": "tsc",
"start": "node dist/server.js",
"docker:build": "docker build -t bolt-ai-docker .",
"docker:run": "docker run -p 3000:3000 bolt-ai-docker"
},
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"@types/express": "^4.17.15",
"typescript": "^4.9.5"
}
}
build
and start
commands if your project uses a different structure or build process.
docker:build
script to build your Docker image:
npm run docker:build
docker:run
script:
npm run docker:run
0.0.0.0:3000
inside the container, and Docker maps it to your host’s port 3000.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.