1

I currently have a new server setup where I have Docker running. I use Gitlab CI to create and push new images. I just fail to determine how to deploy/setup my project files and docker images.

To understand my situation, imagine having a PHP project with the following folder structure

  • system
  • src
  • public
  • users
  • uploads

This is a made-up structure but does reflect the situation where everything except the uploads folder contains PHP scripts.

I could now either go with a separate nginx and php image to run this project, or with a single image containing both these services.

However, this is where my question marks appear. What approach should I take? Because:

  1. Creating both a nginx and php image would duplicate my project files over both images, making 2x100mb images. Sidenote: uploads will be mounted from the host system.
  2. Creating 1 single image with both services should eliminate the above but comes with other problems, e.g. logging and service management.
  3. Creating a data container would also resolve the 2 image sizes and eliminate the problems from point 2, but this is considered bad practices.
  4. According to the documentation I am supposed to use data volumes on host to share data between the containers. This would eliminate the data container, but I would than have to have my build process also deploy the project files to the shared data volume, which I think I'd rather not have as this somewhat defeats the purpose of having containers.
  5. I also don't see how the previous point (point 4 to be precise) should work/be setup. Would I have a build step in Gitlab that creates a volume and copies all the project files to the volume to mount it at a later time to the php and nginx containers?

Also, I just run docker on my server, as I have no need for solutions like Kubernetes or Rancher.

1 Answer 1

1

To manage an application composed by N service I suggesting you to take a look of docker-compose, easy to install, it just manage the docker app for you with some feature like dependency.

To share the data between container volumes is the best solution, if one of the container need to just read the data you can mount the volume as Read Only the volume are host accessible and persistent (until you delete them) so you do not have to create it during the build process. I use it in a django project with nginx as front end, static file are served by nginx from a docker volume where django container wrote them. you can create before start the container the volume by run docker volume create volume_name popolate with your project files and start the containers, manually with docker run or with docker-compose

References: https://docs.docker.com/compose/

3
  • I know about docker-compose, which I also use locally to develop and mount my files. But this is not used on production (yet) as my main question is how to share the data in between the containers. From what I understand from your response there is a way to populate the volume with data on start of the container? That would mean just having 1 container with the files and persist them to the volume so others can read them as well?
    – Roberto
    Commented Jan 3, 2019 at 12:35
  • 1
    docker will create the volume, if not exist, at container start, you could create an entry-point script which clone, if not exist your project data, and pull, if exist, from a git repository in to the volume folder I suggest git but also other solution there. And yes, you can mount same volume to many containers in ReadOnly or ReadWrite -v vol_name:/mount/point:ro for ReadOnly and can be accessed to many containers.
    – AtomiX84
    Commented Jan 3, 2019 at 12:42
  • I think I can work this out. Have a environment var to state where the image is hosted. If it's on prod than it should copy to the volume, otherwise do nothing (cause locally I'd just mount the project files). I think I can make this work. Thanks!
    – Roberto
    Commented Jan 3, 2019 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .