Comments (3)
Hi @BurningDog,
- I don't know very well either docker swarm but it seems that it is necessary to mention the
image
name on the service. Something like this :
php:
image: php
build:
context: .
target: symfony_php
....
And before, you will have to create the image beforehand and just use image property.
-
For the switch, unfortunately I couldn't help you... But look at the docker swarm side, with tags from the image, there may be a management on this side that allows to attach / detach a service juste like for the scale.
-
With redis, I recommend you to use https://github.com/snc/SncRedisBundle for session and cache.
Note: Don't forget also the managed file store for uploads or other. (the Flysytem library is very interesting for this purpose)
I hope this will help you
from symfony-docker.
I've ended up writing a bash script which does a blue/green deployment with the php container, extending this idea here: https://coderbook.com/@marcus/how-to-do-zero-downtime-deployments-of-docker-containers/
Unfortunately that means duplicating the entire php
service in docker-compose.yml
, calling one php-blue
and the other php-green
, but it works.
I've created a new environment variable, PHP_CONTAINER=php-blue
, and in the Caddyfile I've set php_fastcgi {$PHP_CONTAINER}:9000
. On deploy, I check whether blue or green is active, then spin up the other. Once the container is successfully running, tell Caddy to use it.
Like so:
#!/bin/sh
# Uses the blue-green deployment pattern to spin up a new container then tell Caddy to use it.
if [ $(docker ps -f name=php-blue -q) ]
then
ENV="php-green"
OLD="php-blue"
else
ENV="php-blue"
OLD="php-green"
fi
# Output colours - see https://stackoverflow.com/a/5947802/339213
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
DOCKER_COMPOSE="SYMFONY_VERSION=4.4.* PHP_VERSION=7.4 docker-compose --env-file=.env.local -f docker-compose.yml -f docker-compose.prod.yml"
echo -e "${BLUE}DEPLOY${NC} Rebuilding and starting "$ENV" container"
eval $DOCKER_COMPOSE up -d --build $ENV
# Give it max 2 minutes
i=0
while ! docker ps -f name=$ENV | grep healthy
do
sleep 1s
((i=i+1))
if [ $i -eq 120 ]
then
echo -e "${RED}DEPLOY${NC} Timed out after 2 minutes."
exit 1
fi
done
echo -e "${BLUE}DEPLOY${NC} Switching Caddy from $OLD to $ENV"
docker-compose exec -e PHP_CONTAINER=$ENV caddy caddy reload -config /etc/caddy/Caddyfile
echo -e "${BLUE}DEPLOY${NC} Caddy switched from $OLD to $ENV"
echo -e "${BLUE}DEPLOY${NC} Waiting..."
sleep 5s
echo -e "${BLUE}DEPLOY${NC} Stopping "$OLD" container"
docker-compose stop $OLD
Is there a better way of doing this?
2 php containers also means that sessions need to be moved to something like Redis, so I've added that into my docker-compose.yml
file along with a redis
network which is also used be the php containers. This requires adding the following into php/conf.d/symfony.prod.ini
:
session.save_handler = redis
session.save_path = "tcp://redis:6379?weight=1&timeout=2.5"
from symfony-docker.
I closed it due to lack of activity. Do not hesitate to reopen the issue if needed.
from symfony-docker.
Related Issues (20)
- Service 'php' failed to build : Build failed HOT 1
- How to run multiple projects HOT 4
- Run as a different user HOT 7
- cdn.jsdelivr.net importmap:install ERROR Curl HOT 4
- invalid interpolation format for services.php.environment.TRUSTED_HOSTS HOT 1
- Too stupid for recipes HOT 4
- Is mecure required for production? HOT 1
- Unable to connect to external database HOT 1
- Could this repo be converted to a symfony recipe? HOT 1
- Unable to boot app in production mode HOT 2
- Large number of entities cause ORM mapping to break HOT 9
- .env.prod.local not picked up on docker compose up HOT 4
- Unable to deploy in production HOT 3
- invalid interpolation format for services.php.environment.TRUSTED_HOSTS HOT 1
- Informations about my github ci file HOT 1
- Serving Symfony Welcome Page with Docker Compose Opens phpinfo() Instead HOT 2
- Cannot install some PHP extention HOT 1
- Docker escape error HOT 1
- container no run
- Mariadb Connexion lost HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from symfony-docker.