skip to Main Content

i’m trying to override the context.xml file on a docker container using volume mapping feature on docker-compose file

volumes:
  - /tmp/project/context.xml /opt/apache-tomcat/webapps/project/METAINF/context.xml

the problem is that METAINF directory contains other files and when mounting the volumes docker deletes the files keeping only the context.xml file
is there a way to map only the context.xml file without deleting the other files ?
PS: docker-compose version is 2.1

2

Answers


  1. Chosen as BEST ANSWER

    I don't see why it's different for me.

    my docker-compose file:

    version: '2.1'
    
    services:
     project:
      
      image: ${DOCKER_REGISTRY}/project/project-projectaccess:07.07.00-build412
      container_name : project-projectaccess
      environment :
        - JMX_HOST=${HOST_IP} 
        - JMX_PORT=8582 
      volumes: 
        - ./context.xml:/opt/apache-tomcat/webapps/projectaccess/META-INF/context.xml
        - /applis/project/logs/tomcat/:/opt/apache-tomcat/logs/
     
      ports:
        - 8080:8080
        - 8961:8961  
    

    this is when i try to mount the context.xml file

    [root@vm config]# docker exec 013820c5e8af  ls -al  /opt/apache-tomcat/webapps/project/META-INF/
    total 4
    drwxr-xr-x 2 root root  25 Jul 15 16:15 .
    drwxr-xr-x 3 root root  22 Jul 15 16:15 ..
    -rw-r--r-- 1 root root 681 Jul 15 16:14 context.xml
    

    when i'm not mounting the volume

    [root@vm config]# docker exec 3c60b806a574  ls -al  /opt/apache-tomcat/webapps/project/META-INF/    total 8
    drwxr-x--- 3 project tomcat  76 Jul 15 16:13 .
    drwxr-x--- 4 project tomcat  37 Jul 15 16:13 ..
    -rw-r----- 1 project tomcat  91 Jun 23 12:44 MANIFEST.MF
    -rw-r----- 1 project tomcat 560 Jun 23 12:44 context.xml
    drwxr-x--- 3 project tomcat  41 Jul 15 16:13 maven
    -rw-r----- 1 project tomcat   0 Jun 23 12:44 war-tracker
    

  2. It is absolutely possible to mount a single file without replacing the directory. What you are trying should Just Work. You haven’t provided enough information for us to reproduce your specific problem, but here’s an example:

    I don’t have a tomcat application handy, so let’s assume I want to replace the file /etc/issue with a local file.

    I would structure my docker-compose.yaml like this:

    services:
      web:
        image: docker.io/alpinelinux/darkhttpd
        volumes:
          - ./issue:/etc/issue
    

    Assuming that my local issue file contains:

    This is a test
    

    Then after brining up this environment…

    docker compose up -d
    

    …the /etc directory still contains all the expected files:

    $ docker compose exec web ls /etc
    alpine-release   group-           modprobe.d       opt              protocols        shells
    apk              hostname         modules          os-release       resolv.conf      ssl
    busybox-paths.d  hosts            modules-load.d   passwd           secfixes.d       ssl1.1
    conf.d           init.d           motd             passwd-          securetty        sysctl.conf
    crontabs         inittab          mtab             periodic         services         sysctl.d
    fstab            issue            network          profile          shadow           udhcpd.conf
    group            logrotate.d      nsswitch.conf    profile.d        shadow-
    

    But /etc/issue has my custom content:

    $ docker compose exec web cat /etc/issue
    This is a test
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search