I have a docker-compose file with a Postgres image. The service definition is as follows:
<code>services:
postgres:
image: postgres:latest
container_name: postgres
volumes:
- "{{ docker_dir }}/postgressql/data:/var/lib/postgressql/data"
- "{{ docker_compose_dir }}/postgres/initdb:/docker-entrypoint-initdb.d"
environment:
POSTGRES_DB : '{{ container_variables.postgres.db }}'
POSTGRES_USER : '{{ container_variables.postgres.db_user }}'
POSTGRES_PASSWORD : '{{ container_variables.postgres.db_password }}'
networks:
- backend
restart: unless-stopped
command: ["sh","-c","chmod +x /docker-entrypoint-initdb.d/custom_entrypoint.sh && /docker-entrypoint-initdb.d/custom_entrypoint.sh"]
</code>
<code>services:
postgres:
image: postgres:latest
container_name: postgres
volumes:
- "{{ docker_dir }}/postgressql/data:/var/lib/postgressql/data"
- "{{ docker_compose_dir }}/postgres/initdb:/docker-entrypoint-initdb.d"
environment:
POSTGRES_DB : '{{ container_variables.postgres.db }}'
POSTGRES_USER : '{{ container_variables.postgres.db_user }}'
POSTGRES_PASSWORD : '{{ container_variables.postgres.db_password }}'
networks:
- backend
restart: unless-stopped
command: ["sh","-c","chmod +x /docker-entrypoint-initdb.d/custom_entrypoint.sh && /docker-entrypoint-initdb.d/custom_entrypoint.sh"]
</code>
services:
postgres:
image: postgres:latest
container_name: postgres
volumes:
- "{{ docker_dir }}/postgressql/data:/var/lib/postgressql/data"
- "{{ docker_compose_dir }}/postgres/initdb:/docker-entrypoint-initdb.d"
environment:
POSTGRES_DB : '{{ container_variables.postgres.db }}'
POSTGRES_USER : '{{ container_variables.postgres.db_user }}'
POSTGRES_PASSWORD : '{{ container_variables.postgres.db_password }}'
networks:
- backend
restart: unless-stopped
command: ["sh","-c","chmod +x /docker-entrypoint-initdb.d/custom_entrypoint.sh && /docker-entrypoint-initdb.d/custom_entrypoint.sh"]
I want to execute a shell script after starting the container.
<code>#!/bin/bash
set -e
until pg_isready -h postgres -p 5432 -U postgres
do
echo "Waiting for postgres"
sleep 10;
done
echo "do something ...."
</code>
<code>#!/bin/bash
set -e
until pg_isready -h postgres -p 5432 -U postgres
do
echo "Waiting for postgres"
sleep 10;
done
echo "do something ...."
</code>
#!/bin/bash
set -e
until pg_isready -h postgres -p 5432 -U postgres
do
echo "Waiting for postgres"
sleep 10;
done
echo "do something ...."
At container startup, I receive the following output in the log:
<code>Waiting for postgres
postgres:5432 - no response
</code>
<code>Waiting for postgres
postgres:5432 - no response
</code>
Waiting for postgres
postgres:5432 - no response
Even if I replace the execution of the shell script with a simple echo, I still can’t get the container to run. When I start the container without the command, it works perfectly