Raidri
Raidri

Reputation: 55

Empty volume folder after docker-compose up

I have a dockerfile which load some Stuff from composer in a vendor folder on the container. Now I want to link the vendor folder on the container with my host enviroment. If I start the service with docker-compose up the vendor folder is empty. What can I do to keep the data on the container?

Here is my dockerfile:

FROM php:7.3.3-apache-stretch
RUN apt-get update && \
apt-get install -y --no-install-recommends nano \
git \
openssh-server

RUN curl -s https://getcomposer.org/installer | php && \
echo "{}" > composer.json && \
php composer.phar require slim/slim "^3.0" && \
chown -R www-data. .

VOLUME /var/www/html/vendor

And here my docker-compose.yml:

version: '3.2'
services:
  slim:
    build:
      context: ./slim
    ports:
      - "1337:1337"
    networks:
      - backend
    volumes:
      - ./slim/vendor:/var/www/html/vendor
networks:
  backend:

thanks for the help

Upvotes: 1

Views: 1956

Answers (1)

Mihai
Mihai

Reputation: 10717

What you see is expected behaviour.

If you want the vendor folder populated and available on the host as well then you have to run the installation AFTER the mapping is happening, not the other way round.

This command:

curl -s https://getcomposer.org/installer | php && \
echo "{}" > composer.json && \
php composer.phar require slim/slim "^3.0" && \
chown -R www-data. .

should become your ENTRYPOINT or CMD so that it is run when the container starts (not when it is built).

I would suggest to put those commands in an install script and run that. It would look cleaner and easier to understand.

Hope this helps but if you need more information just let me know.

Upvotes: 2

Related Questions