У меня есть проект с 4 images, которые запускаются как 5 сервисов, через docker-compose
version: '3.1'
services:
nginx-api:
image: nginx
depends_on:
- api
ports:
- "3001:443"
environment:
NODE_TLS_REJECT_UNAUTHORIZED: 0
volumes:
- ./api/api.nginx.site:/etc/nginx/conf.d/default.conf
- ./api/certs/.:/etc/nginx/certs
api:
build: api/.
command: yarn start
depends_on:
- db
environment:
NODE_TLS_REJECT_UNAUTHORIZED: 0
NODE_ENV: development
COOKIE_SECRET: ChangeMe1234
env_file:
- api/.env
ports:
- '8080:3000'
volumes:
- ./api/.:/opt/app
- /opt/app/node_modules
nginx-frontend:
image: nginx
depends_on:
- frontend
ports:
- "3000:443"
environment:
NODE_TLS_REJECT_UNAUTHORIZED: 0
volumes:
- ./frontend/frontend.nginx.site:/etc/nginx/conf.d/default.conf
- ./frontend/certs/.:/etc/nginx/certs
frontend:
build: frontend/.
command: yarn start
environment:
NODE_TLS_REJECT_UNAUTHORIZED: 0
NODE_ENV: development
COOKIE_SECRET: ChangeMe1234
API_URL: "https://nginx-api"
ports:
- "0.0.0.0:3030:3000"
volumes:
- ./frontend/.:/opt/frontend
- /opt/frontend/node_modules
db:
build: db/.
environment:
NODE_TLS_REJECT_UNAUTHORIZED: 0
POSTGRES_PASSWORD: localdev
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- ./db/postgres-data:/var/lib/postgresql/data/pgdata
ports:
- '8001:5432'
Что я сейчас делаю:
Создал ECS кластер( Registered container instances 5),
По отдельности собрал image api, frontend, db, nginx и загрузил в репозиторий aws
Зарегистрировал их все как Task.
Запустил на кластере db и frontend, api не запустился.
Как теперь запустить nginx?
Можно это как то сделать проще, а не руками?
Что осталось сделать для запуска всех контейнеров на сервере?
Вот вопрос на github к бойлерплейту(только бд другая немного)
https://github.com/chadfurman/rpg-boilerplate/issues/19
PS Все это локально запускается через скрипт docker/run.sh
#!/bin/bash
set -e
COMPOSE_PROJECT_NAME=rpgboilerplate
# Linux fix
CONFIG_FILE=docker-compose.yml
CACHE_INIT=false
SERVICES=(api frontend)
SERVICES_DIR=(api frontend)
BUILD_CMD="docker-compose -f $CONFIG_FILE build"
UP_CMD="docker-compose -f $CONFIG_FILE up"
function rmContainers() {
echo "Removing containers"
docker-compose -f $CONFIG_FILE rm -fv $SERVICE_NAME || true
}
function initCache() {
# Init empty cache file
touch $SERVICE_DIR/yarn.lock
if [ ! -f $SERVICE_DIR/.yarn-cache.tgz ]; then
echo "Init empty $SERVICE_DIR/.yarn-cache.tgz"
tar cvzf $SERVICE_DIR/.yarn-cache.tgz --files-from /dev/null
CACHE_INIT=true
fi
}
function retrieveYarnCache() {
echo "Checking if I need to retrieve Yarn cache and lock file for $SERVICE_NAME"
RETRIEVE=false
# Case #1: we initialized an empty cache (usually, first run after cloning)
if [ "$CACHE_INIT" = true ]; then
RETRIEVE=true
fi
# Case #2: yarn packages changed during build
docker run --rm --entrypoint cat ${COMPOSE_PROJECT_NAME}_$SERVICE_NAME:latest /cache/yarn.lock > /tmp/${SERVICE_NAME}_yarn.lock
if ! diff -q $SERVICE_DIR/yarn.lock /tmp/${SERVICE_NAME}_yarn.lock > /dev/null 2>&1; then
RETRIEVE=true
fi
if [ "$RETRIEVE" = true ]; then
echo "Retrieving"
docker run --rm --entrypoint cat ${COMPOSE_PROJECT_NAME}_$SERVICE_NAME:latest /.yarn-cache.tgz > $SERVICE_DIR/.yarn-cache.tgz
cp /tmp/${SERVICE_NAME}_yarn.lock $SERVICE_DIR/yarn.lock
else
echo "Not retrieving"
fi
echo "Done"
}
for i in "${!SERVICES[@]}"
do
SERVICE_NAME=${SERVICES[$i]} SERVICE_DIR=${SERVICES_DIR[$i]} rmContainers
SERVICE_NAME=${SERVICES[$i]} SERVICE_DIR=${SERVICES_DIR[$i]} initCache
done
COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME $BUILD_CMD
for i in "${!SERVICES[@]}"
do
SERVICE_NAME=${SERVICES[$i]} SERVICE_DIR=${SERVICES_DIR[$i]} retrieveYarnCache
done
COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME $UP_CMD