Method implementation of dockerfile echo specifying multiple lines of text for a file
- 2021-06-28 14:28:32
- OfStack
Add multiple lines to the specified file in dockerfile, noting the'$'symbol after echo
[root@master01 ovn-node]# cat dockerfile
FROM ovn-node:2.11.2
# sed Delete the specified line
RUN sed -i '53d' /root/start-ovs.sh
# use echo Add multi-line content
RUN echo $'OVERLAY_ENDPOINT=`hostname -i`\n\
ovs-vsctl set open . external-ids:ovn-encap-ip=${OVERLAY_ENDPOINT}\n\
\n\
# create a bridge , then mapping outside port\n\
ovs-vsctl add-br br-ex\n\
ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=phyNet:br-ex\n\
\n\
# add nic
ovs-vsctl add-port br-ex ${OVN_PHYNET_NIC}\n\
\n\
tail -f /var/log/openvswitch/ovs-vswitchd.log\n'\
>> /root/start-ovs.sh
CMD ["/bin/bash","/root/start-ovs.sh"]
Result: Note that the'#'comment line in the multi-line text is not entered into the specified file
[root@master01 ovn-node]# cat /root/start-ovs.sh
# Set remote ovn-sb for ovn-controller to connect to
ovs-vsctl set open . external-ids:ovn-remote=tcp:${OVN_SB_SERVICE_HOST}:${OVN_SB_SERVICE_PORT}
ovs-vsctl set open . external-ids:ovn-encap-type=geneve
OVERLAY_ENDPOINT=`hostname -i`
ovs-vsctl set open . external-ids:ovn-encap-ip=${OVERLAY_ENDPOINT}
ovs-vsctl add-br br-ex
ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=phyNet:br-ex
ovs-vsctl add-port br-ex ${OVN_PHYNET_NIC}
tail -f /var/log/openvswitch/ovs-vswitchd.log