# Yugabyte Docker container Init Script

**URL:** <https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671>\
**Category:** General\
**Created:** [July 7, 2022, 8:07pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671 "2022-07-07T20:07:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/ganesh/32/555_2.png) [@Ganesh](https://forum.yugabyte.com/u/Ganesh)\
**Post date:** [July 7, 2022, 8:07pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/1 "2022-07-07T20:07:10Z")

</div>

Hi All,  
I am creating single node master and tablet server using docker -compose file as mentioned below.

version: ‘2’

volumes:  
yb-master-data-1:  
yb-tserver-data-1:

services:  
yb-master:  
image: yugabytedb/yugabyte:latest  
container\_name: yb-master-n1  
volumes:  
- yb-master-data-1:/mnt/master  
- ./src/test/resources/data.sql:/docker-entrypoint-initidb.d  
command: [ “/home/yugabyte/bin/yb-master”,  
“–fs\_data\_dirs=/mnt/master”,  
“–master\_addresses=yb-master-n1:7100”,  
“–rpc\_bind\_addresses=yb-master-n1:7100”,  
“–replication\_factor=1”]  
ports:  
- “7000:7000”  
environment:  
SERVICE\_7000\_NAME: yb-master

yb-tserver:  
image: yugabytedb/yugabyte:latest  
container\_name: yb-tserver-n1  
volumes:  
- yb-tserver-data-1:/mnt/tserver  
- ./src/test/resources/data.sql:/docker-entrypoint-initidb.d  
command: [ “/home/yugabyte/bin/yb-tserver”,  
“–fs\_data\_dirs=/mnt/tserver”,  
“–start\_pgsql\_proxy”,  
“–rpc\_bind\_addresses=yb-tserver-n1:9100”,  
“–tserver\_master\_addrs=yb-master-n1:7100”]  
ports:  
- “9042:9042”  
- “5433:5433”  
- “9000:9000”  
environment:  
SERVICE\_5433\_NAME: ysql  
SERVICE\_9042\_NAME: ycql  
SERVICE\_6379\_NAME: yedis  
SERVICE\_9000\_NAME: yb-tserver  
depends\_on:  
- yb-master

I need to run seed / init scripts after database is created. I tried using volume mount my sql file using

- ./src/test/resources/data.sql:/docker-entrypoint-initidb.d

However these scripts are not executed. Is there any other way i can achieve this.

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [July 7, 2022, 9:15pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/2 "2022-07-07T21:15:58Z")

</div>

Hi Ganesh,  
I use a side service like this for that:

```auto
  yb-demo-init:
      image: yugabytedb/yugabyte:latest
      volumes:
          - ./scripts:/home/yugabyte/scripts
      command: |
       bash -c "
        bin/ysqlsh v ON_ERROR_STOP=1 -c 'select * from yb_servers()' &&
         ./scripts/script.sh
       "
      deploy:
          restart_policy:
             condition: on-failure

```

---

<div class="post-metadata">

**Author:** ![Ganesh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/ganesh/32/555_2.png) [@Ganesh](https://forum.yugabyte.com/u/Ganesh)\
**Post date:** [July 12, 2022, 6:11pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/3 "2022-07-12T18:11:42Z")

</div>

Hi Franck,

Thank you for information. I am trying to run bash script like this on yugabyte tablet server to run my init script data.sql. However ysqlsh command is not getting executed by docker container.  
Strange behaviour that i have observed is, after execution of command “yb-tserver” the ysqlsh command is not getting executed. There are no failure logs .

```auto
#!/bin/bash
ipaddress=`hostname -I | cut -f1 -d' '`
/home/yugabyte/bin/yb-tserver --fs_data_dirs=/mnt/tserver --start_pgsql_proxy --rpc_bind_addresses=yb-tserver-n1:9100 --tserver_master_addrs=yb-master-n1:7100
ysqlsh -h $ipaddress -f /docker-entrypoint-initidb.d

```

Regards,  
Ganesh

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [July 14, 2022, 2:53pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/4 "2022-07-14T14:53:59Z")

</div>

Hi Ganesh, I think the 5433 port is not immediately opened but that should show an error message

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [July 14, 2022, 2:55pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/5 "2022-07-14T14:55:40Z")

</div>

thinking about it, `yb-tserver` doesn’t go to the background, that’s the reason

Note that for simple configuration we have a `yugabyted` service that starts `yb-master` and `yb-tserver` in the background

---

<div class="post-metadata">

**Author:** ![Ganesh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/ganesh/32/555_2.png) [@Ganesh](https://forum.yugabyte.com/u/Ganesh)\
**Post date:** [July 15, 2022, 2:21pm UTC](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/6 "2022-07-15T14:21:06Z")

</div>

Thank you Franck, !!!  
Got it.  
However , I achieved the intended result other way using spring boot.
