Search code examples
dockerdocker-composeignite

How to mount ignite data to host system


I would like to run apache-ignite in docker and I am able to do that. But the problem is whenever I spin the image and creates the tables in ignite it stays there as long as that container is running. If I restart the container or starts the ignite image again I did not get that data. I know whenever we spins the images it always creates the new container. In my case if I want to persist the data then I need to commit and push the container so that next start I will get it.

But is there any way, where I can store ignite data on host system and whenever I start the image it will read/write the data on that location (in short volume mounting).

Can anyone please share there experience or thought with example? Thanks.

I am using this with docker-compose and below is my docker-compose.yml file.

version: "3.7"
services:
  ignite:
    image: apacheignite/ignite
    environment:
      - IGNITE_QUIET=false
    volumes:
      - "./ignite-main.xml:/opt/ignite/apache-ignite/config/default-config.xml"
    ports:
      - 11211:11211
      - 47100:47100
      - 47500:47500
      - 49112:49112

If I run the docker-compose up command then I get the below error.

Recreating ignite-test_ignite_1 ... done
Attaching to ignite-test_ignite_1
ignite_1  | Ignite Command Line Startup, ver. 2.7.0#20181130-sha1:256ae401
ignite_1  | 2018 Copyright(C) Apache Software Foundation
ignite_1  | 
ignite_1  | class org.apache.ignite.IgniteException: Failed to instantiate Spring XML application context [springUrl=file:/opt/ignite/apache-ignite/config/default-config.xml, err=Line 1 in XML document from URL [file:/opt/ignite/apache-ignite/config/default-config.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 31; cvc-elt.1: Cannot find the declaration of element 'property'.]

Solution

  • @Update Hello, After doing lots of RnD I able to solve this issue. Below are the configuration I made 1. docker-compose.yml

    version: "3.5"
        services:
          ignite:
            image: apacheignite/ignite
            environment:
              - IGNITE_QUIET=false
    
            volumes:
              - ignite-persistence-1:/opt/ignite/
              - "./ignite_1.xml:/opt/ignite/apache-ignite/config/default-config.xml"
    
            ports:
              - 11211:11211
              - 47100:47100
              - 47500:47500
              - 49112:49112
    
            deploy:
              replicas: 1
              restart_policy:
                condition: on-failure
                delay: 30s
                max_attempts: 10
                window: 180s
    
        volumes:
          ignite-persistence-1:
    
    1. ignite_1.xml for data persistence

                   http://www.apache.org/licenses/LICENSE-2.0
    
              Unless required by applicable law or agreed to in writing, software
              distributed under the License is distributed on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
              See the License for the specific language governing permissions and
              limitations under the License.
            -->
            <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd">
               <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
                  <!-- Enabling Apache Ignite Persistent Store. -->
                  <property name="dataStorageConfiguration">
                     <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                        <property name="defaultDataRegionConfiguration">
                           <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                              <property name="persistenceEnabled" value="true" />
                           </bean>
                        </property>
                     </bean>
                  </property>
                  <property name="workDirectory" value="/opt/ignite/apache-ignite/data" />
                  <!-- Explicitly configure TCP discovery SPI to provide a list of initial nodes. -->
                  <property name="discoverySpi">
                     <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                        <property name="ipFinder">
                           <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
                           <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
                           <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                              <property name="addresses">
                                 <list>
                                    <!-- In distributed environment, replace with actual host IP address. -->
                                    <value>127.0.0.1:47500..47502</value>
                                 </list>
                              </property>
                           </bean>
                        </property>
                     </bean>
                  </property>
               </bean>
            </beans>
    

    I kept docker-compose.yml and ignite_1.xml in same directory and opened the terminal from this directory and executed the below command.

    docker-compose up

    By using ignite-persistence-1:/opt/ignite/ I was able to persist the data even if I stop or down the docker-compose.

    I hope this will help others as well.

    Thanks.