4

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:

  • New service 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.
  • Copy code in PHP image or Nginx image?

Which is the best option?

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.