Docker Community Forums

Share and learn in the Docker community.

Create symlink on bookmarked container volume

I’m trying to setup symbolic links inside volume excluded folders by bookmarking them. Considering bookmarked folders are not linked to host, I thought it would be possible to create symlinks inside my container, but no. Is there any way to achieve this goal? I have a legacy repository with multiple projects (applications) inside the same repository and a Common folder that would be symlinked within all these apps folders. For development environment purposes I need to use a VOLUME to reload my browser with the updated code.

I’ve tried to point volume like /dev/null:/var/www/html/CommonFolder instead of bookmarking, also without success.

Thanks in advance.

docker-compose.yml:

version: '3'

services:
  app:
    build:
      dockerfile: Dockerfile
      context: ./
    ports:
      - 8080:80
    volumes:
      - .:/var/www/html # references to host
      - /var/www/html/CommonFolder # bookmark
      - /var/www/html/TargetFolder1/BookmarkedFolder1 # bookmark
      - /var/www/html/TargetFolder1/BookmarkedFolder2 # bookmark
      - /var/www/html/TargetFolder2/BookmarkedFolder1 # bookmark
      - /var/www/html/TargetFolder2/BookmarkedFolder2 # bookmark
      - /var/www/html/TargetFolder3/BookmarkedFolder1 # bookmark
      - /var/www/html/TargetFolder3/BookmarkedFolder2 # bookmark

Dockerfile:

FROM php:7.4.19-apache
# REMOVED UNNECESSARY LINES

# /var/www/html points to host
WORKDIR /var/www/html

COPY ./Common .

RUN for i in TargetFolder1 TargetFolder2 TargetFolder3; do \
    rm -Rf "/var/www/html/$i/BookmarkedFolder1" && \
    ln -s "/var/www/html/CommonFolder/Folder1" "/var/www/html/$i/BookmarkedFolder1" && \
    rm -Rf "/var/www/html/$i/BookmarkedFolder2" && \
    ln -s "/var/www/html/CommonFolder/Folder2" "/var/www/html/$i/BookmarkedFolder2" \
    ; done

EXPOSE 80

CMD ["/usr/sbin/apache2ctl", "-DFOREGROUND"]