I'm using Docker and Docker compose for a PHP-FPM/Nginx/Mariadb application development. I want to use it now in production with Docker swarm and docker-compose v3 (via docker-stack.yml)
My docker-stack file is like that:
version: "3"
services:
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
php:
image: <MYREGISTRY>/php
volumes:
- app-data:/var/www/app
deploy:
replicas: 2
nginx:
image: <MYREGISTRY>/nginx
depends_on:
- php
volumes:
- app-data:/var/www/app
deploy:
replicas: 2
ports:
- "80:80"
volumes:
app-data:
As you can see I use my own private registry to store applications images. My question is where do I put my code source?
I see 2 options:
app (based on busybox image?) to be a data-only container. Then I can push code source image to my registry and deploy. It can be convenient to have a Docker image with tagged code source.Which is the best option?
The maintenance of the source code should be independent of the maintenance of the docker images. By pushing a docker image containing the source code, into the registry, only to maintain the source code, your first option seems to mix the two together.
Keep the source code on a VCS (version control system). When the code is ready to be distributed, build a docker image with that code. It'd be less overall maintenance if the image has access to the source code directly from the VCS.
You could explore multi-stage docker builds, where temporary containers can be created which connect to the VCS, pulls the appropriate code and builds it if necessary. Then the final image only copies the result of the build process from the temp container, without needing unnecessary access to the VCS.