Py学习  »  docker

如何在docker镜像中替换conf文件中的文本

Yogesh Kushwaha • 5 年前 • 1927 次点击  

我试图建立一个Docker映像,在那里我需要在父目录下用逗号分隔的目录列表,并在复制到容器中的配置文件中设置,但在conf文件中文本永远不会被替换。下面是Docker的图片。或 Github Link

FROM ubuntu:16.04
LABEL maintainer="TEST"

RUN apt-get update && apt-get install vim git -y

COPY odoo.conf /etc/odoo/odoo.cfg

RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world1
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world2
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world3
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world4

COPY setup.sh /setup.sh
RUN ["chmod", "+x", "/setup.sh"]
CMD ["/setup.sh"]

搜索和替换发生在 setup.sh 但进入外壳永远不会显示出替代品。但是,如果我在容器shell中执行命令/setup.sh,它就会执行该任务。

有兴趣知道,怎么做,我做错了什么?

塞特普什

# get addons path
addons_path=`ls -d /mnt/extra-addons/* | paste -d, -s`
# can't use / because directory name contains, using #
sed -i -e "s#__addons__path__#${addons_path}#" /etc/odoo/odoo.cfg

/etc/odoo/odoo.conf文件

[options]
addons_path = __addons__path__
data_dir = /var/lib/odoo
.......

预期 /etc/odoo/odoo.conf文件

[options]
addons_path = /mnt/extra-addons/hellow-world1,/mnt/extra-addons/hellow-world2,/mnt/extra-addons/hellow-world3,/mnt/extra-addons/hellow-world4
data_dir = /var/lib/odoo

γ更新 我删除了intermediate setup.sh,并在dockerfile中完成了整个操作,看起来像

FROM ubuntu:16.04
LABEL maintainer="TEST"

RUN apt-get update && apt-get install vim git -y

COPY odoo.conf /etc/odoo/odoo.cfg

RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world1
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world2
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world3
RUN git clone https://github.com/kelseyhightower/helloworld.git /mnt/extra-addons/hellow-world4
ENV addons_path=$(ls -d /mnt/extra-addons/* | paste -d, -s)  ## Fails here it sets blank so sed command works but the variable addons_path doesn't have the value probably I am defining variable wrongly?
RUN sed -i -e "s#__addons__path__#$addons_path#" /etc/odoo/odoo.cfg
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44980
 
1927 次点击  
文章 [ 3 ]  |  最新文章 5 年前