# Initdb with a docker stack

**URL:** <https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182>\
**Category:** General\
**Created:** [August 3, 2023, 11:17am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182 "2023-08-03T11:17:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.yugabyte.com/u/Guillaume)\
**Post date:** [August 3, 2023, 11:17am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/1 "2023-08-03T11:17:20Z")

</div>

Hello everybody,

I come back on a subject already discuss with no real solution on a system approach.  
I start a docker stack with a yb-master and a yb-tserver. This stack must be use by an other application but this one can’t start because it miss a table and a piece of sql code is given to create this table.  
I thought “nice, yugabytedb is postgres compatible, I could the a initdb start to inject my sql”. After a while I read [this subject](https://forum.yugabyte.com/t/does-yugabyte-support-initialization-scripts/1185/2) who said in sumary that this feature is not implemented.  
Well , searching again I found [this one](https://forum.yugabyte.com/t/yugabyte-docker-container-init-script/1671/2) where @FranckPachot propose to use a third docker service to inject the code. Right , I’m not so bad because I thought to the same thing. But When I’m trying this way, it does’nt work. My yb-tserve refuse the connection with this message :

> LOG: invalid length of startup packet

Is t here someone who have an idea to soluce this situation ?  
PS \> I’m an sysadmin, not a dev 🤒

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [August 3, 2023, 11:46am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/2 "2023-08-03T11:46:15Z")

</div>

Hi @Guillaume

Can you describe exactly the commands that you ran & at what order and the full error message?

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.yugabyte.com/u/Guillaume)\
**Post date:** [August 3, 2023, 11:49am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/3 "2023-08-03T11:49:54Z")

</div>

Hi Dorian

My third docker service , the one who ‘replace/follow’ the initdb is like this :

```auto
  init-tserver:
    image: yugabytedb/yugabyte:2.16.6.0-b43
    environment:
      CQLSH_HOST: "yb-tserver"
      CQLSH_PORT: 5433
      CQLSH_USER: "postgres"
    command: 'bash -c bin/ycqlsh -f ./initdb.sql'
    volumes:
      - './pginit/initdb.sql:/home/yugabyte/initdb.sql:ro'
    depends_on:
      - yb-tserver

```

The log from it is :

> yugabytedb-init-tserver-1 | Connection error: (‘Unable to connect to any servers’, {‘192.168.176.2’: ConnectionShutdown(‘Connection to 192.168.176.2 was closed’,)})  
> yugabytedb-init-tserver-1 exited with code 1

The log from yb-tserver is :

> yugabytedb-yb-tserver-1 | 2023-08-03 11:05:29.255 UTC [110] LOG: invalid length of startup packet

I add in case of my tserver service :

```auto
  yb-tserver:
    image: yugabytedb/yugabyte:2.16.6.0-b43
    hostname: ybtserver2
    ports:
      - 9000:9000 # UI Tservev
      - 9100:9100 # port RPC YB-TServer
      - 5433:5433 # YSQL
    command: 'bin/yb-tserver --flagfile tserver.conf'
    volumes:
      - './tserver.conf:/home/yugabyte/tserver.conf:ro'
      - 'tserver_disk0:/mnt/disk0:rw'
      - 'tserver_disk1:/mnt/disk1:rw'

```

In addition, again, my initdb.sql file is just few lines to add a table

```auto
CREATE TABLE IF NOT EXISTS filemeta (
  dirhash BIGINT,
  name VARCHAR(65535),
  directory VARCHAR(65535),
  meta bytea,
  PRIMARY KEY (dirhash, name)
);

```

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [August 9, 2023, 8:08am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/4 "2023-08-09T08:08:38Z")

</div>

cc @FranckPachot for any insights

---

<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:** [August 9, 2023, 6:31pm UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/5 "2023-08-09T18:31:32Z")

</div>

Hi @Guillaume, today I use `yugabyted` that starts `yb-master` and `yb-tserver` and has some automations like starting scripts from a directory, moving to replication factor 3 when there are 3 nodes, starting a new GUI…  
If your goal is to have the same behavior as the PostgreSQL image, I build an image with similar behavior: [GitHub - FranckPachot/yb-pglike: Builds a docker image with YugabyteDB that is compatible with the PostgreSQL image for a drop-in replacement](https://github.com/FranckPachot/yb-pglike/tree/main)

---

<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:** [August 9, 2023, 6:32pm UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/6 "2023-08-09T18:32:26Z")

</div>

I think I got it. In your docker compose, I see `bin/ycqlsh -f ./initdb.sql` and CQLSH variables. Note that the PostgreSQL API is Y **S** QL (and the command line is `ysqlsh`. Y **C** QL is the cassandra like API. `invalid length of startup packet` may come from sending to the PostgreSQL endpoint (5433) from with the Cassandra protocol.

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.yugabyte.com/u/Guillaume)\
**Post date:** [August 10, 2023, 9:39am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/7 "2023-08-10T09:39:12Z")

</div>

Hello @FranckPachot , thank your for yours answers.

> [@FranckPachot](#):
>
> Hi @Guillaume, today I use `yugabyted` that starts `yb-master` and `yb-tserver` and has some automations like starting scripts from a directory, moving to replication factor 3 when there are 3 nodes, starting a new GUI…

I’m not sure to understand.  
Do you mean I can launch my services `yb-master` and `yb-tserver` with a starting sql script who will initialise my database ?  
If yes, how can I do that ? I try a lot of things without success.

( I note you’re Swiss, may be you speak french ? 🙂 )

---

<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:** [August 10, 2023, 10:33am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/8 "2023-08-10T10:33:06Z")

</div>

Oui 🙂  
En fait yugabyted (d pour daemon) est un utilitaire qui lance les yb-master et yb-tserver et fait des choses en plus, comme lancer un script d’init: [yugabyted reference | YugabyteDB Docs](https://docs.yugabyte.com/preview/reference/configuration/yugabyted/#start)

Il y a un example sympa ici: [How to run yugabytedb in docker and docker-compose](https://citizix.com/how-to-run-yugabytedb-in-docker-and-docker-compose/)  
Il suffit de rajouter `--initial_scripts_dir` pour lancer tous les scripts `.sql` du directory

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.yugabyte.com/u/Guillaume)\
**Post date:** [August 10, 2023, 10:58am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/9 "2023-08-10T10:58:51Z")

</div>

Merci beaucoup, je vais regarder tout cela, n’ayant pas réussi a lancé yugabyted pour créer un cluster je n’étais pas aller plus loin. Je me suis raté quelque part de toute évidence.  
Merci pour ces liens je vais regarder de plus près.

---

<div class="post-metadata">

**Author:** ![Guillaume](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@Guillaume](https://forum.yugabyte.com/u/Guillaume)\
**Post date:** [August 10, 2023, 2:22pm UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/10 "2023-08-10T14:22:13Z")

</div>

Et navré @FranckPachot , de retour avec une question. J’ai tenté d’utiliser le flag --config dans le lancement du conteneur avec bin/yugabyted mais il me dit :

> yugadb-yugabyte-1 | ERROR:root: | 0.0s | Failed to read config file /home/yugabyte/yugabyte.conf: Expecting value: line 1 column 1 (char 0)  
> yugadb-yugabyte-1 | Failed to read config file /home/yugabyte/yugabyte.conf: Expecting value: line 1 column 1 (char 0)

Ma commande docker est celle ci :

```auto
services:
  yugabyte:
    image: yugabytedb/yugabyte:2.16.6.0-b43
    restart: always
    command: bin/yugabyted start --base_dir=/home/yugabyte/yb_data --config /home/yugabyte/yugabyte.conf --daemon=false
    ports:
      - 7000:7000
      - 5433:5433
      - 9000:9000
      - 9042:9042
    volumes:
      - yugabyte_db:/var/lib/yugabyteql/data
      - ./yugabyte.conf:/home/yugabyte/yugabyte.conf:ro
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=yugabyte

```

Avec un fichier de le configuration suivant étant donné qu’on est hors réseau :

```auto
--callhome false

```

J’ai également testé

```auto
--callhome=false

```

Est ce qu’il y a un formalisme particulier ?

---

<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:** [August 14, 2023, 8:18am UTC](https://forum.yugabyte.com/t/initdb-with-a-docker-stack/2182/11 "2023-08-14T08:18:10Z")

</div>

Ah oui, ce fichier de config est en format JSON.  
Mais je ne pense pas que ce soit possible de passer des paramètres. C’est `yugabyted` qui y met les paramètres pour le prochain restart

La doc devrait le préciser, merci pour le feedback
