I have the following dockerfile (elided):
FROM postgres:latest
1 ARG VERSION
2
3 # install clojure
4 RUN apt-get update
5 RUN apt-get -y install curl
6 RUN curl -O https://download.clojure.org/install/linux-install-1.10.3.933.sh
7 RUN chmod +x linux-install-1.10.3.933.sh
8 RUN ./linux-install-1.10.3.933.sh
9
10 # postgres
11 RUN apt-get -y install sudo
12 USER postgres
13 RUN initdb
14 RUN postgres -D /var/lib/postgresql/data
15
16 RUN psql -f bin/sql/postgres-db.sql -U postgres
17 RUN psql -f bin/sql/postgres-table.sql -U postgres -d datomic
18 RUN psql -f bin/sql/postgres-user.sql -U postgres -d datomic
But after running the command on line 14, the docker container stops executing the rest of the commands, which manually should be run in another shell while the postgres -D command is active. How do I run the postgres command in the background?
I tried & at the end of line 14 to send it in background, but get this:
[+] Building 4.4s (14/25)
=> [internal] load build definition from Dockerfile_db 0.0s
=> => transferring dockerfile: 1.29kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/postgres:latest 3.7s
=> [internal] load build context 0.0s
=> => transferring context: 175B 0.0s
=> [ 1/21] FROM docker.io/library/postgres:latest@sha256:6647385dd9ae11a 0.0s
=> CACHED [ 2/21] RUN apt-get update 0.0s
=> CACHED [ 3/21] RUN apt-get -y install curl 0.0s
=> CACHED [ 4/21] RUN curl -O https://download.clojure.org/install/linux 0.0s
=> CACHED [ 5/21] RUN chmod +x linux-install-1.10.3.933.sh 0.0s
=> CACHED [ 6/21] RUN ./linux-install-1.10.3.933.sh 0.0s
=> CACHED [ 7/21] RUN apt-get -y install sudo 0.0s
=> CACHED [ 8/21] RUN initdb 0.0s
=> [ 9/21] RUN postgres -D /var/lib/postgresql/data & 0.3s
=> ERROR [10/21] RUN psql -f bin/sql/postgres-db.sql -U postgres 0.4s
------
> [10/21] RUN psql -f bin/sql/postgres-db.sql -U postgres:
#13 0.367 psql: error: could not connect to server: No such file or directory
#13 0.367 Is the server running locally and accepting
#13 0.367 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
------
executor failed running [/bin/sh -c psql -f bin/sql/postgres-db.sql -U postgres]: exit code: 2