Если мы сделаем 10 таких образов с разными приложениями, то их обшая часть - базовый образ - будет одна и та же и не будет занимать отдельного места.
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const dotenv = require('dotenv').config()
esbuild.build({
entryPoints: ['./src/main.ts'],
bundle: true,
platform: 'node',
tsconfig: "tsconfig.json",
define: {
"process.env.JWT_SECRET": "\"supercat\"",
"process.env.PORT": "\"4000\"",
"process.env.HOST": "\"http://localhost:4200\"",
"process.env.MONGO_IP_PROD": `\"${process.env.MONGO_IP_PROD}\"`
},
minify: true,
outfile: '../../dist/backend/server.js',
plugins: [nodeExternalsPlugin()],
});
my-mongoserver:
# build will get tagged with 'image'
image: 259ecd4a0a0e
container_name: my-mongoserver
ports:
- 4000:4000
command: node dist/backend/server.js
environment:
- MONGO_IP_PROD=my-mongodb
networks:
- test
depends_on:
- my-mongodb
servers: Map(1) {
my-mongoserver | 'undefined:27017' => ServerDescription {
my-mongoserver | address: 'undefined:27017',
А ещё нормально сделать свой базовый образ с node.js и основными пакетами, которые везде используются, а затем на базе него делать образы под конкретные приложения.
docker cp "C:\Program Files\MongoDB\Tools\100\bin\dump\you_need" b2fb5a13f4d8:/bin
Error: No such container:path: b2fb5a13f4d8:\
version: '3.6'
# Deploys MongoDB with customization scripts and container with Mongo client
# https://fabianlee.org/2018/05/20/docker-using-docker-compose-to-link-a-mongodb-server-and-client/
#
# usage:
# sudo docker-compose build
# sudo docker-compose up
services:
my-mongodb:
image: 0850fead9327
container_name: my-mongodb
ports:
- 27017:27017
environment:
- MONGO_INITDB_DATABASE=you_need
- MONGO_INITDB_ROOT_USERNAME=
- MONGO_INITDB_ROOT_PASSWORD=
volumes:
# seeding scripts
- ./mongo-entrypoint:/docker-entrypoint-initdb.d
# named volumes
- mongodb:/data/db
- mongoconfig:/data/configdb
networks:
- test
my-mongoclient:
# build will get tagged with 'image'
build: .
image: 5db0a73c35fe
container_name: my-mongoclient
ports:
- 4200:4200
environment:
- MONGO_IP=my-mongodb
- MONGO_INITDB_DATABASE=you_need
- MONGO_INITDB_ROOT_USERNAME=
- MONGO_INITDB_ROOT_PASSWORD=
networks:
- test
depends_on:
- my-mongodb
volumes:
# default dir on Ubuntu: /var/lib/docker/volumes
mongodb:
mongoconfig:
networks:
test:
driver: bridge
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const dotenv = require('dotenv').config()
esbuild.build({
entryPoints: ['./src/main.ts'],
bundle: true,
platform: 'node',
tsconfig: "tsconfig.json",
define: {
"process.env.JWT_SECRET": "\"supercat\"",
"process.env.PORT": "\"4000\"",
"process.env.HOST": "\"http://localhost:4200\"",
"process.env.MONGO_IP": `\"${process.env.MONGO_IP}\"`
},
minify: true,
outfile: '../../dist/backend/server.js',
plugins: [nodeExternalsPlugin()],
});
import { MongoClient } from "mongodb";
import { QueryModel } from "../../models/databases/mongodb/query.model";
const url = `mongodb://${process.env.MONGO_IP}`;
const dbName = 'you_need';
export async function query(collection_name: string): Promise<QueryModel> {
const client = new MongoClient(url);
await client.connect();
console.log('Connected successfully to server');
const db = client.db(dbName);
const collection = db.collection(collection_name);
return {
collection,
client
};
}
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
esbuild.build({
entryPoints: ['./src/main.ts'],
bundle: true,
platform: 'node',
tsconfig: "tsconfig.json",
define: {
"process.env.JWT_SECRET": "\"supercat\"",
"process.env.PORT": "\"4000\"",
"process.env.HOST": "\"http://localhost:4200\"",
"process.env.MONGO_IP": `\"my-mongodb:27017\"`
},
minify: true,
outfile: '../../dist/backend/server.js',
plugins: [nodeExternalsPlugin()],
});