简体   繁体   English

覆盖 Docker 容器中的文件

[英]Overwrite file in Docker Container

I have jira8 running in a docker container:我在 docker 容器中运行 jira8:

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. 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在 jira8 docker 容器中。

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 .我可以 - 在容器启动后 - 将server-localhost-8.10.xml手动复制到 docker 容器中,覆盖默认server.xml

I tried mounting read only ( :ro )我尝试安装只读( :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?使安装的文件只读并始终覆盖 docker 容器中存在的文件?

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).该图像有一个Docker Hub 页面(通常, https://hub.docker.com/r/owner/image用于非库图像)。 That links to a Bitbucket repo for its Docker packaging source.它链接到Bitbucket 存储库,用于其 Docker 封装源。 The main container process is an entrypoint.py script that unconditionally does:主容器进程是一个无条件执行的entrypoint.py脚本

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.其中gen_cfg function将通过从引用的 Jinja2 源文件中渲染来覆盖命名的 output 文件。

The Docker Hub page lists out a pretty large number of environment-variable settings. Docker Hub 页面列出了大量的环境变量设置。 If you set those, the container will produce its own server.xml file for you.如果您设置了这些,容器将为您生成自己的server.xml文件。 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.如果你能弄清楚到底注入了什么,你也可以使用绑定挂载来覆盖server.xml.j2源文件。

(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.) (通常,在启动时绑定挂载总是将内容推送到容器中,并且从不从镜像中提取内容。这个镜像在生成自己的配置时有点不寻常,这就是主机文件被覆盖的原因;这不是自然发生的事情与 Docker。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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