Installing Smarty in a Docker Composer Container?

I am currently learning Docker and looking to move one of my web-sites to a container to allow quick and easy redeployment/recovery.

I have a working YAML file for the container, but am struggling to get the Smarty files written to persistent storage - see below…

Can anyone tell me what I am doing wrong ?

Thanks

version: "3"
services:
  smarty_installer:
    image: composer
    volumes:
      - volSmarty:/vendor
    command: require smarty/smarty
  webserver:
    image: php:apache
    ports:
      - 32001:80
    volumes:
      - volHTML:/var/www/html
    restart: always
volumes:
  volHTML:
    driver: local
    driver_opts:
      type: cifs
      device: ${path}/html
      o: username=${uid},password=${pwd},uid=1000,gid=1000
  volSmarty:
    driver: local
    driver_opts:
      type: cifs
      device: ${path}/smarty
      o: username=${uid},password=${pwd},uid=1000,gid=1000
networks: {}

There is no such thing as Docker Compose container. Compose is just a way to describe how you want to start a container.

You should also share some details about what your problam is. Saying only that it doesn’t work and let people find out why your config would be wrong if it is wrong gets you much fewer replies if it gets any. So why do you think its wrong? Do you have error messages?

As I said - I am learning :grinning:

My problem is, when smarty is installed, the files are installed within the container. The container then exits and the files go with it. I am trying to install the Smarty files to persistent storage so they can be used by a PHP / Apache container, but I can’t work out how to handle the volume within the smarty_installer.

Hope that explains it better?

But what is wrong with your current solution? You are using volumes. What happens?

after the install, nothing is written to the mapped volume.

I am assuming (but this is where my lack of knowledge is kicking in) that Smarty is being installed then the container exits and the installed files vanish as they are not persistent as my Volumes id is not working.

Not sure how to debug what is happening to the installed files.

Do you really need a samba/Windows fileshare? And where do your variables come from? the lowercase path, pwd and uid? PATH, PWD and UID could exists automatically on Linux or macOS, the lowercase variants would needed to be set somewhere. And where is the server IP address? Is it set in “path”? You could try a simple bind mount to see if the content appears locally.

services:
  smarty_installer:
    image: composer
    volumes:
      - ./vendor:/vendor
    command: require smarty/smarty

You can also search for similar issues like this

The environmental variables are all supplied and correct (as I have used these on other containers). The SMB mount is established, but Smarty isn’t installing to the persistent storage; it is something to do with the way Smarty is installing - not the SMB aspect.

I think I will give up on this approach and manually install Smarty.

It is not about Smarty. Smarty is a PHP library and can be installed via PHP composer. All the files downloaded by the composer are saved in “vendor” by default. What you won’t have if you only have “vendor” as volume is the composer.lock file and composer.json which is also changed by the require command. There is also a composer home which could be required sometimes.

I don’t use the composer image because I always use the same image to run composer which I use to start the application container. That way I can make sure that all the system dependencies are installed and if not, composer can warn me about it.

But if you read the official image description, you can find that the working directory in the composer container is /app. So when you run the composer container vendor will be /app/vendor and not /vendor. That is why the folder is empty.

https://hub.docker.com/_/composer

Ah thanks :grinning: I will give this a try.

As part of my learning could you share how you use the same image to run composer and then start the application? I am assuming this means files installed by composer are then available to the application? When I have tried to do this, I end up with two containers and the installer one is exited, meaning the environment (as I understand it) has gone and is not available to the Web App I have started.

Appreciate this is all very newbie stuff, but I am trying to learn - honest :grinning:

I had a project to demonstrate how I use Composer with Docker, but I didn’t have time to finish it and it didn’t actually work properly. To be honest I’m not an active PHP developer, I just have some projects from time to time and sometimes I just start the container interactively. Initialize the vendor folder manually and when I build the final image, I copy the vendor folder. I cans till share my project on GitHub, but as I wrote it is still not finished and I don’t know when I will have time to do it:

The main idea is that I use a shell script to start the composer container.

But when I had to use it for a Symfony project, the script couldn’t run. I don’t remember why. On the other hand, I wanted to make this composer script work for everyone for every project which made it harder to make it work, but I would definitely use some scripts to start the composer container based on the application image (but adding git and libzip-dev (or zip) and openssh-client), generate the vendor and mount it to the application container. Also making sure the owner of the files is the same as the user that needs it in the container.

I guess you could alternatively use a multi-stage build including the composer install which generates the vendo folder and run docker build --target composer_install . --output ./vendor/ before running docker compose up. I don’t have time to explain it better right now, but if you search for the mentioned parameters like target and output in the context of multi-stage build, you will find examples.

Many thanks for this. I will take a look and try and follow how this works.

Phil