简体   繁体   中英

Overwrite file in Docker Container

I have jira8 running in a docker container:

jira8:
  container_name: jira8
  expose:
    - "8080"
  image: atlassian/jira-software:8.10
  networks:
    atlassian-network:
      aliases:
        - jira8
  ports:
    - "8081:8080"
  restart: always
  volumes:
    - /Users/mles/git/jira-migration/config-files/server-localhost-8.10.xml:/opt/atlassian/jira/conf/server.xml

Everytime I restart the docker container, the file /Users/mles/git/jira-migration/config-files/server-localhost-8.10.xml gets overwritten with the file present at /opt/atlassian/jira/conf/server.xml in the jira8 docker container.

I could - after the start of the container - copy the server-localhost-8.10.xml manually into the docker container, overwriting the default server.xml .

I tried mounting read only ( :ro )

  volumes:
    - /Users/mles/git/jira-migration/config-files/server-localhost-8.10.xml:/opt/atlassian/jira/conf/server.xml:ro

but my file on the host still gets overwritten.

Is there a better way to do this? f.ex.making the mounted files read only and always overwriting the files present in the docker container?

You'll need to use this image's native setup system, or heavily patch it.

The image has a Docker Hub page (in general, https://hub.docker.com/r/owner/image for non-library images). That links to a Bitbucket repo for its Docker packaging source. The main container process is an entrypoint.py script that unconditionally does:

gen_cfg('server.xml.j2', f'{JIRA_INSTALL_DIR}/conf/server.xml')

where that gen_cfg function will overwrite the named output file by rendering it from the referenced Jinja2 source file.

The Docker Hub page lists out a pretty large number of environment-variable settings. If you set those, the container will produce its own server.xml file for you. If you can figure out what exactly is being injected, you can also use a bind mount to overwrite the server.xml.j2 source file.

(In general, bind mounts at startup time always push content into the container, and never extract content from the image. This image is slightly unusual in generating its own configuration and that's why the host file is getting overwritten; it's not something that naturally happens with Docker.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM