Loading s7nsa_11_images...
... services: ... frontend: # image: nginx:alpine build: ./mini_nginx ...
# start from an existing image FROM alpine
# run this command in the guest system (package installation) RUN apk add --no-cache nginx envsubst
# create a working directory and execute every remaining command from it WORKDIR /mini_nginx
# copy the specified file(s) from the host to the working directory COPY mini_nginx.sh .
# run this command by default (from the working directory) CMD ["/bin/sh", "mini_nginx.sh"]
#!/bin/sh set -e # exit script on any failure
NGINX_PORT=${NGINX_PORT:-80} NGINX_HTTPS_PORT=${NGINX_HTTPS_PORT:-443} vars=`env | sed -re 's/(.*)=.*/${\1}/'` mkdir -p /etc/nginx/templates for f in /etc/nginx/templates/*.template ; do [ -f "${f}" ] || continue c='/etc/nginx/http.d/'`basename "${f}" .template` echo "generating ${c}" envsubst "${vars}" <"${f}" >"${c}" done echo "starting nginx server" exec nginx -g 'daemon off;'
... services: ... db: # image: postgres:alpine build: ./mini_postgres ...
# start from an existing image FROM alpine
# run this command in the guest system (package installation) RUN apk add --no-cache postgresql
# create a working directory and execute every remaining command from it WORKDIR /mini_postgres
# copy the specified file(s) from the host to the working directory COPY mini_postgres.sh .
# run this command by default (from the working directory) CMD ["/bin/sh", "mini_postgres.sh"]
#!/bin/sh set -e # exit script on any failure
missing="" for n in POSTGRES_DB POSTGRES_USER POSTGRES_PASSWORD ; do eval v=\"\$${n}\" if [ -z "${v}" ] ; then echo "expected value for variable ${n}" missing="${missing} ${n}" fi done [ -z "${missing}" ] || exit 1
PG_MAJOR=`postgres -V | awk '{print $3}' | cut -d. -f1` PGDATA=/var/lib/postgresql/${PG_MAJOR}/docker for d in ${PGDATA} /run/postgresql ; do mkdir -p ${d} chown -R postgres:postgres ${d} done mkdir -p /docker-entrypoint-initdb.d exec su postgres <<EOF if [ ! -f ${PGDATA}/PG_VERSION ] ; then echo "initialising database" initdb -D ${PGDATA} echo "host all all all scram-sha-256" >>${PGDATA}/pg_hba.conf pg_ctl -D ${PGDATA} -o "-c listen_addresses='localhost'" -w start psql -c "CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}'" psql -c "CREATE DATABASE ${POSTGRES_DB} OWNER ${POSTGRES_USER};" for f in /docker-entrypoint-initdb.d/*.sql ; do [ -f "\${f}" ] || continue PGPASSWORD='${POSTGRES_PASSWORD}' psql -U ${POSTGRES_USER} \ -d ${POSTGRES_DB} -v ON_ERROR_STOP=1 <"\${f}" done pg_ctl -D ${PGDATA} -m fast -w stop fi echo "starting postgres server" exec postgres -D ${PGDATA} -c listen_addresses='*' EOF
app_demo_2 ├── ... ├── rs_backend │ ├── Cargo.toml │ ├── Dockerfile │ └── src │ └── main.rs └── ...
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # builder image #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# start from an existing image FROM rust:alpine AS builder
# create a working directory and execute every remaining command from it WORKDIR /app
# copy the specified file(s) from the host to the working directory COPY Cargo.toml .
# run this command in the guest system (dependency compilation in cache) RUN --mount=type=cache,target=/app/target \ mkdir src && echo 'fn main() {}' >src/main.rs && cargo build --release
# copy the specified file(s) from the host to the working directory COPY src/ src/
# run this command in the guest system (program compilation) RUN --mount=type=cache,target=/app/target \ find src -exec touch {} + \ && cargo build --release && cp target/release/rs_backend .
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # final image #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# start from an EMPTY image FROM scratch
# copy the compiled program from the builder image COPY --from=builder /app/rs_backend /
# run this command by default ENTRYPOINT ["/rs_backend"]
... services: ... backend: # build: ./py_backend build: ./rs_backend ...
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # builder image #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# start from an existing image FROM alpine AS builder
# run this command in the guest system (package installation) RUN apk add --no-cache curl build-base linux-headers bison flex perl
# run this command in the guest system (source code download) ARG PGV=18.4 RUN curl -L \ https://ftp.postgresql.org/pub/source/v${PGV}/postgresql-${PGV}.tar.gz \ | tar xz
# go to the working directory and execute every remaining command from it WORKDIR /postgresql-${PGV}
# run this command in the guest system (program compilation) RUN ./configure --prefix=/opt/postgres \ --without-icu --without-readline --without-zlib --without-llvm \ --without-tcl --without-perl --without-python --without-gssapi \ --without-pam --without-bsd-auth --without-ldap --without-bonjour \ --without-selinux --without-systemd --without-libedit-preferred \ --without-liburing --without-libcurl --without-libnuma \ --without-libxml --without-libxslt --without-lz4 --without-zstd \ --without-openssl \ --disable-nls --disable-debug --disable-profiling --disable-coverage \ --disable-dtrace --disable-tap-test --disable-injection-point \ --disable-depend --disable-cassert \ && make -j$(nproc) \ && make install \ && strip /opt/postgres/bin/* \ && ( strip /opt/postgres/lib/*.so* || true )
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # final image #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# start from an existing image FROM alpine
# run this command in the guest system (package installation) RUN apk add --no-cache musl-locales
# copy the compiled programs from the builder image to the final image COPY --from=builder /opt/postgres/bin/postgres \ /opt/postgres/bin/initdb \ /opt/postgres/bin/pg_ctl \ /opt/postgres/bin/psql \ /usr/bin COPY --from=builder /opt/postgres/lib/libpq.so.5 \ /opt/postgres/lib/dict_snowball.so \ /opt/postgres/lib/plpgsql.so \ /usr/lib COPY --from=builder /opt/postgres/share \ /usr/share
# run this command in the guest system (user declaration) RUN echo 'postgres:x:70:70::/var/lib/postgresql:/bin/sh' >>/etc/passwd \ && echo 'postgres:x:70:' >>/etc/group \ && echo 'postgres:!::0:::::' >>/etc/shadow
# create a working directory and execute every remaining command from it WORKDIR /mini_postgres
# copy the specified file(s) from the host to the working directory COPY mini_postgres.sh .
# run this command by default (from the working directory) CMD ["/bin/sh", "mini_postgres.sh"]