_ZSt28__throw_bad_array_new_lengthv symbol not found - postgresql

I want to write a Dockerfile in which I can specify the version of the extensions. But I have a problem when I run this docker file I get an error in timescale part
Error relocating /usr/bin/cmake: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7reserveEv: symbol not found
Error relocating /usr/bin/cmake: _ZSt28__throw_bad_array_new_lengthv: symbol not found
The command '/bin/sh -c set -ex && apk add --no-cache --virtual .fetch-deps build-base ca-certificates git tar && apk add --no-cache --virtual .build-deps --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing make cmake gcc clang clang-dev g++ llvm-dev dpkg dpkg-dev util-linux-dev libc-dev coreutils && apk add --no-cache --virtual .timescaledb-rundeps openssl libstdc++ openssl-dev && wget -O timescaledb.tar.gz "https://github.com/timescale/timescaledb/archive/$TIMESCALEDB_VERSION.tar.gz" && echo "$TIMESCALEDB_SHA256 timescaledb.tar.gz" | sha256sum -c - && mkdir -p /usr/src/timescaledb && tar --extract --file timescaledb.tar.gz --directory /usr/src/timescaledb --strip-components 1 && rm timescaledb.tar.gz && cd /usr/src/timescaledb && ./bootstrap -DPROJECT_INSTALL_METHOD="docker" -DREGRESS_CHECKS=OFF && cd ./build && make install && cd / && rm -rf /usr/src/timescaledb && apk del .fetch-deps .build-deps && sed -r -i "s/[#]\s*(shared_preload_libraries)\s*=\s*'(.)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample' returned a non-zero code: 127
##[error]The command '/bin/sh -c set -ex && apk add --no-cache --virtual .fetch-deps build-base ca-certificates git tar && apk add --no-cache --virtual .build-deps --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing make cmake gcc clang clang-dev g++ llvm-dev dpkg dpkg-dev util-linux-dev libc-dev coreutils && apk add --no-cache --virtual .timescaledb-rundeps openssl libstdc++ openssl-dev && wget -O timescaledb.tar.gz "https://github.com/timescale/timescaledb/archive/$TIMESCALEDB_VERSION.tar.gz" && echo "$TIMESCALEDB_SHA256 timescaledb.tar.gz" | sha256sum -c - && mkdir -p /usr/src/timescaledb && tar --extract --file timescaledb.tar.gz --directory /usr/src/timescaledb --strip-components 1 && rm timescaledb.tar.gz && cd /usr/src/timescaledb && ./bootstrap -DPROJECT_INSTALL_METHOD="docker" -DREGRESS_CHECKS=OFF && cd ./build && make install && cd / && rm -rf /usr/src/timescaledb && apk del .fetch-deps .build-deps && sed -r -i "s/[#]\s(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample' returned a non-zero code: 127
##[error]The process '/usr/bin/docker' failed with exit code 127
could you please help me. Thanks
# https://github.com/docker-library/postgres/blob/master/13/alpine/Dockerfile
FROM postgres:13.4-alpine
# https://postgis.net/docs/manual-3.1/postgis_installation.html
ENV POSTGIS_VERSION 3.1.4
ENV POSTGIS_SHA256 dfcbad0c6090c80bc59d3ea77d1adc4b3ade533a403761b4af6d9a44be1a6e48
RUN set -ex \
\
&& apk add --no-cache --virtual .fetch-deps ca-certificates openssl tar \
\
&& wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \
&& echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/postgis \
&& tar \
--extract \
--file postgis.tar.gz \
--directory /usr/src/postgis \
--strip-components 1 \
&& rm postgis.tar.gz \
\
&& apk add --no-cache --virtual .build-deps \
autoconf automake json-c-dev libtool libxml2-dev make perl llvm clang clang-dev \
\
&& apk add --no-cache --virtual .build-deps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
g++ gdal-dev geos-dev proj-dev protobuf-c-dev \
&& cd /usr/src/postgis \
&& ./autogen.sh \
&& ./configure \
&& make \
&& make install \
&& apk add --no-cache --virtual .postgis-rundeps \
json-c \
&& apk add --no-cache --virtual .postgis-rundeps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
geos gdal proj protobuf-c libstdc++ \
&& cd / \
&& rm -rf /usr/src/postgis \
&& apk del .fetch-deps .build-deps .build-deps-edge
# https://docs.timescale.com/timescaledb/latest/how-to-guides/install-timescaledb/self-hosted/ubuntu/installation-source
ENV TIMESCALEDB_VERSION 2.4.2
ENV TIMESCALEDB_SHA256 b206a376251259eb745eee819e7a853b3fbab9dc8443303714484a0fef89a2a4
RUN set -ex \
&& apk add --no-cache --virtual .fetch-deps \
build-base \
ca-certificates \
git \
tar \
&& apk add --no-cache --virtual .build-deps \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
make \
cmake \
gcc \
clang \
clang-dev \
g++ \
llvm-dev \
dpkg \
dpkg-dev \
util-linux-dev \
libc-dev \
coreutils \
&& apk add --no-cache --virtual .timescaledb-rundeps \
openssl \
libstdc++ \
openssl-dev \
\
&& wget -O timescaledb.tar.gz "https://github.com/timescale/timescaledb/archive/$TIMESCALEDB_VERSION.tar.gz" \
&& echo "$TIMESCALEDB_SHA256 *timescaledb.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/timescaledb \
&& tar \
--extract \
--file timescaledb.tar.gz \
--directory /usr/src/timescaledb \
--strip-components 1 \
&& rm timescaledb.tar.gz \
\
&& cd /usr/src/timescaledb \
&& ./bootstrap -DPROJECT_INSTALL_METHOD="docker" -DREGRESS_CHECKS=OFF \
&& cd ./build && make install \
\
&& cd / \
&& rm -rf /usr/src/timescaledb \
&& apk del .fetch-deps .build-deps \
&& sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample
COPY ./init-postgis.sh /docker-entrypoint-initdb.d/1.postgis.sh
COPY ./init-timescaledb.sh /docker-entrypoint-initdb.d/2.timescaledb.sh
COPY ./init-postgres.sh /docker-entrypoint-initdb.d/3.postgres.sh

Related

Alpine edge failed - ERROR: unsatisfiable constraints: so:libgdbm.so.4 (missing):

Today I faced with error when try to build my container with alpine:edge
There is my Dockerfile:
FROM alpine:edge
RUN apk add --update --no-cache \
coreutils \
php7-fpm \
php7-apcu \
php7-ctype \
php7-curl \
php7-dom \
php7-gd \
php7-iconv \
php7-imagick \
php7-json \
php7-intl \
php7-mcrypt \
php7-fileinfo\
php7-mbstring \
php7-opcache \
php7-openssl \
php7-pdo \
php7-pdo_mysql \
php7-mysqli \
php7-pdo_pgsql \
php7-pgsql \
php7-xml \
php7-zlib \
php7-phar \
php7-tokenizer \
php7-session \
php7-simplexml \
php7-xdebug \
php7-zip \
php7-xmlwriter \
make \
curl \
zlib-dev \
libxml2-dev \
rabbitmq-c-dev \
oniguruma-dev \
php7-pecl-amqp \
php7-amqp \
php7-redis \
openrc --no-cache \
supervisor
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ php7-pecl-mongodb
COPY docker-entrypoint.sh /opt/docker-entrypoint.sh
RUN echo "$(curl -sS https://composer.github.io/installer.sig) -" > composer-setup.php.sig \
&& curl -sS https://getcomposer.org/installer | tee composer-setup.php | sha384sum -c composer-setup.php.sig \
&& php composer-setup.php && rm composer-setup.php* \
&& chmod +x composer.phar && mv composer.phar /usr/bin/composer && chmod +x /opt/docker-entrypoint.sh
COPY symfony.ini /etc/php7/conf.d/
COPY symfony.ini /etc/php7/cli/conf.d/
COPY xdebug.ini /etc/php7/conf.d/
COPY symfony.pool.conf /etc/php7/php-fpm.d/
WORKDIR /var/www/symfony
ENTRYPOINT ["ash", "/opt/docker-entrypoint.sh"]
EXPOSE 9001
end error:
ERROR: unsatisfiable constraints:
so:libgdbm.so.4 (missing):
required by: python3-3.8.5-r1[so:libgdbm.so.4]
libsasl-2.1.27-r9[so:libgdbm.so.4]
when I added this problem resolved, but why I faced with error exactly today ?
FROM alpine:edge
LABEL maintainer="Vincent Composieux <vincent.composieux#gmail.com>"
RUN apk update && apk upgrade && \
apk add --update --no-cache --update-cache vips-dev fftw-dev build-base \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/community/ \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/main
RUN apk add --update --no-cache \
coreutils \

why do cp command get error without noting add -e option?

Premise · What I want to realize
I've getting an error into writing a Dockerfile, so I'm worried about a getting error.
That command is cp.
testing environment
base container image centos:7
My laptop is MacBook Pro (it may not need info, isn't it?)
What I did
the Dockerfile is here,
FROM centos:7 # Official centos image. this is a comment for asking here.
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk \
SCALA_HOME=/usr/local/scala \
SCALA_VERSION=scala-2.13.0
WORKDIR /usr/local/lib/
RUN : " *** nginx install ***" \
&& { \
echo '[nginx-stable]'; \
echo 'name=nginx stable repo'; \
echo 'baseurl=http://nginx.org/packages/centos/$releasever/$basearch/'; \
echo 'gpgcheck=1'; \
echo 'enabled=1'; \
echo 'gpgkey=https://nginx.org/keys/nginx_signing.key'; \
echo 'gpgkey=https://nginx.org/keys/nginx_signing.key'; \
} > /etc/yum.repos.d/nginx.repo \
&& yum install -y nginx \
&& yum install -y rsyslog \
&& rsyslogd \
&& cp /usr/lib/systemd/system/nginx.service /etc/systemd/system/ \
&& nginx -version \
&& : " *** JDK install ***" \
&& JAVA_HOME=${JAVA_HOME}/bin \
&& PATH=$PATH:${JAVA_HOME}/bin \
&& java -version \
&& javac -version \
&& : "*** Scala install ***" \
&& wget http://downloads.typesafe.com/scala/2.13.0/scala-2.13.0.tgz \
&& tar zxvf scala-2.13.0.tgz \
&& ln -s ${SCALA_VERSION} scala \
&& mkdir ${SCALA_HOME} \
&& mv ${SCALA_VERSION} SCALA_HOME \
&& SCALA_HOME=${SCALA_HOME}/bin >> /etc/profile.d/scala.sh \
&& PATH=$PATH:${SCALA_HOME}/bin >> /etc/profile.d/scala.sh \
&& source /etc/profile.d/scala.sh \
&& cd \
&& scala -version \
&& : "*** sbt install ***" \
&& curl https://bintray.com/sbt/rpm/rpm | tee /etc/yum.repos.d/bintray-sbt-rpm.repo \
&& yum install -y sbt \
&& sbt -version \
&& ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&& yum clean all \
&& mkdir -p /usr/share/app
WORKDIR /usr/share/app
EXPOSE 80
Problems occurring · Error messages
the getting error is,
cp: invalid option -- 'e'
Try 'cp --help' for more information.
umm.., I've completely understand the error.
I haven't cp alias too.
Could you please help me?
If you need more information, feel free asking me.
Regards,
K
i had the same error as you because i wrote the command as below
sudo find /home/usersdata -type f -user mark -exec cp -p -parents {} /official ;
the parameters parents should --parents instead of -parents
For some reasons the error does not provide explicitly what is wrong.
Hope it helps you

ERROR: unsatisfiable constraints when installing PostGIS on the Alpine Docker image

Ok, so the task seems pretty easy! Use an Alpine image (as it is light-weight and secure) to perform some PostgreSQL DB creation/migrations. I'm using the following Dockerfile using the code here:
FROM alpine:latest
RUN apk add -U postgresql
# install PostGIS
ENV POSTGIS_VERSION 2.5.2
ENV POSTGIS_SHA256 225aeaece00a1a6a9af15526af81bef2af27f4c198de820af1367a792ee1d1a9
RUN set -ex \
\
&& apk add --no-cache --virtual .fetch-deps \
ca-certificates \
openssl \
tar \
\
&& wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \
&& echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/postgis \
&& tar \
--extract \
--file postgis.tar.gz \
--directory /usr/src/postgis \
--strip-components 1 \
&& rm postgis.tar.gz \
\
&& apk add --no-cache --virtual .build-deps \
autoconf \
automake \
g++ \
json-c-dev \
libtool \
libxml2-dev \
make \
perl \
\
&& apk add --no-cache --virtual .build-deps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
gdal-dev \
geos-dev \
proj4-dev \
protobuf-c-dev \
&& cd /usr/src/postgis \
&& ./autogen.sh \
# configure options taken from:
# https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/rules?h=jessie
&& ./configure \
# --with-gui \
&& make \
&& make install \
&& apk add --no-cache --virtual .postgis-rundeps \
json-c \
&& apk add --no-cache --virtual .postgis-rundeps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
geos \
gdal \
proj4 \
protobuf-c \
&& cd / \
&& rm -rf /usr/src/postgis \
&& apk del .fetch-deps .build-deps .build-deps-edge
COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]
However, the dependencies are not installed using apk due to some unsatisfiable constraints error. The error is as follows and the full logs are available in this issue I opened.
ERROR: unsatisfiable constraints:
gdal-dev (missing):
required by: .build-deps-edge-20200123.143501[gdal-dev]
geos-dev (missing):
required by: .build-deps-edge-20200123.143501[geos-dev]
proj4-dev (missing):
required by: .build-deps-edge-20200123.143501[proj4-dev]
Any help is appreciated.
The code on github contains another image postgres:11-alpine comparing to image defined in question: alpine:latest.
Packages gdal-dev, geos-dev, protobuf-c-dev are no longer in edge repo testing branch, they were migrated to stable v3.11 repository. Also proj4-dev was renamed to proj-dev, which is also in stable v3.11 repository.
So to fix the Dockerfile we just need to install above packages from v3.11 repo, ie change this part of code:
&& apk add --no-cache --virtual .build-deps \
autoconf \
automake \
g++ \
json-c-dev \
libtool \
libxml2-dev \
make \
perl \
\
&& apk add --no-cache --virtual .build-deps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
gdal-dev \
geos-dev \
proj4-dev \
protobuf-c-dev \
proj4-dev \
protobuf-c-dev \
to this one:
&& apk add --no-cache --virtual .build-deps \
autoconf \
automake \
g++ \
gdal-dev \
geos-dev \
json-c-dev \
libtool \
libxml2-dev \
make \
perl \
proj-dev \
protobuf-c-dev \
\
The final Dockerfile is:
FROM alpine:3.11
RUN apk add -U postgresql
# install PostGIS
ENV POSTGIS_VERSION 2.5.2
ENV POSTGIS_SHA256 225aeaece00a1a6a9af15526af81bef2af27f4c198de820af1367a792ee1d1a9
RUN set -ex \
\
&& apk add --no-cache --virtual .fetch-deps \
ca-certificates \
openssl \
tar \
\
&& wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \
&& echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/postgis \
&& tar \
--extract \
--file postgis.tar.gz \
--directory /usr/src/postgis \
--strip-components 1 \
&& rm postgis.tar.gz \
\
&& apk add --no-cache --virtual .build-deps \
autoconf \
automake \
g++ \
gdal-dev \
geos-dev \
json-c-dev \
libtool \
libxml2-dev \
make \
perl \
proj-dev \
protobuf-c-dev \
\
&& cd /usr/src/postgis \
&& ./autogen.sh \
# configure options taken from:
# https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/rules?h=jessie
&& ./configure \
# --with-gui \
&& make \
&& make install \
&& apk add --no-cache --virtual .postgis-rundeps \
json-c \
&& apk add --no-cache --virtual .postgis-rundeps-edge \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
geos \
gdal \
proj4 \
protobuf-c \
&& cd / \
&& rm -rf /usr/src/postgis \
&& apk del .fetch-deps .build-deps .build-deps-edge
COPY ./db-creator.sh /db-creator.sh
CMD ["./db-creator.sh"]

mongodb container start failed with error:IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating

mongodb docker container start failed with errors: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
I use offical mongodb Dockerfile to build the container, and use docker-compose to start it.
Here is my Dockerfile:
FROM ubuntu:bionic
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" > /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
RUN export all_proxy=http:192.168.1.177:1080
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
jq \
numactl \
; \
if ! command -v ps > /dev/null; then \
apt-get install -y --no-install-recommends procps; \
fi; \
rm -rf /var/lib/apt/lists/*
# grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
ENV GOSU_VERSION 1.11
# grab "js-yaml" for parsing mongod's YAML config files (https://github.com/nodeca/js-yaml/releases)
ENV JSYAML_VERSION 3.13.0
RUN mkdir ~/.gnupg && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
RUN set -ex; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
wget \
; \
if ! command -v gpg > /dev/null; then \
apt-get install -y --no-install-recommends gnupg dirmngr; \
fi; \
rm -rf /var/lib/apt/lists/*; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true; \
\
wget -O /js-yaml.js "https://github.com/nodeca/js-yaml/raw/${JSYAML_VERSION}/dist/js-yaml.js"; \
# TODO some sort of download verification here
\
apt-get purge -y --auto-remove wget
RUN mkdir /docker-entrypoint-initdb.d
ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B
RUN set -ex; \
export GNUPGHOME="$(mktemp -d)"; \
for key in $GPG_KEYS; do \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done; \
gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg; \
command -v gpgconf && gpgconf --kill all || :; \
rm -r "$GNUPGHOME"; \
apt-key list
# Allow build-time overrides (eg. to build image with MongoDB Enterprise version)
# Options for MONGO_PACKAGE: mongodb-org OR mongodb-enterprise
# Options for MONGO_REPO: repo.mongodb.org OR repo.mongodb.com
# Example: docker build --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com .
ARG MONGO_PACKAGE=mongodb-org-unstable
ARG MONGO_REPO=repo.mongodb.org
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
ENV MONGO_MAJOR 4.1
ENV MONGO_VERSION 4.1.10
# bashbrew-architectures:amd64 arm64v8 s390x
RUN echo "deb http://$MONGO_REPO/apt/ubuntu bionic/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR multiverse" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN set -x \
&& apt-get update \
&& apt-get install -y \
${MONGO_PACKAGE}=$MONGO_VERSION \
${MONGO_PACKAGE}-server=$MONGO_VERSION \
${MONGO_PACKAGE}-shell=$MONGO_VERSION \
${MONGO_PACKAGE}-mongos=$MONGO_VERSION \
${MONGO_PACKAGE}-tools=$MONGO_VERSION \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/mongodb \
&& mv /etc/mongod.conf /etc/mongod.conf.orig
RUN mkdir -p /data/db /data/configdb \
&& chown -R mongodb:mongodb /data/db /data/configdb \
&& chmod g+w -R /data/db \
&& chmod g+w -R /data/configdb
VOLUME /data/db /data/configdb
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 27017
CMD ["mongod"]
and docker-compose below:
mongodb:
build: ./dockerfiles/mongodb
volumes:
- ./data/mongodb/db:/data/db
- ./data/mongodb/configdb:/data/configdb
ports:
- 7017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=super
- MONGO_INITDB_ROOT_PASSWORD=123456
restart: always
I expect the container start successfully. But i got failure with :IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
If i remove volumes sections, It works!
The host is ubuntu18.04, and /data is writeable!
I had solved my problem le 老铁!
AS i use vmware to start an Ubuntu server, and shared a folder with windows 7. The container volume on the shared folder.
check the inspect information of the mongodb container.
"Mounts": [
{
"Type": "bind",
"Source": "/mnt/hgfs/ubuntu/dockers/data/mongodb/configdb",
"Destination": "/data/configdb",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/mnt/hgfs/ubuntu/dockers/data/mongodb/db",
"Destination": "/data/db",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
the Source contains string "/mnt/hgfs/ubuntu" tell us: It shared folder!

How to run sql script before the application launches in docker

I'm deploying the project with Asp.net Core, PostgreSql and Docker in Windows 10 (no PostgreSql installed). So I have to run sql script to update data before the application launches (for registering a singleton dependency injection).
The content of my Dockerfile as following:
# TODO use official docker image
FROM microsoft/dotnet:1.1.0-sdk-projectjson
# Install .NET CLI dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \
automake \
bzip2 \
file \
g++ \
gcc \
imagemagick \
libbz2-dev \
libc6-dev \
libcurl4-openssl-dev \
libdb-dev \
libevent-dev \
libffi-dev \
libgdbm-dev \
libgeoip-dev \
libglib2.0-dev \
libjpeg-dev \
libkrb5-dev \
liblzma-dev \
libmagickcore-dev \
libmagickwand-dev \
libmysqlclient-dev \
libncurses-dev \
libpng-dev \
libpq-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libtool \
libwebp-dev \
libxml2-dev \
libxslt-dev \
libyaml-dev \
make \
patch \
xz-utils \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV ASPNETCORE_URLS="http://*:5000"
ENV ASPNETCORE_ENVIRONMENT="Development"
# Copy files to app directory
COPY . /app
# Set working directory
WORKDIR /app
# Restore NuGet packages
RUN ["dotnet", "restore"]
# Build app
RUN ["dotnet", "build"]
#dotnet ef migrations add InitialCreate
RUN ["dotnet", "ef", "migrations", "add", "InitialCreate"]
# Open up port
EXPOSE 5000
CMD chmod +x ./docker-start.sh
CMD bash ./docker-start.sh
And here is the content of docker-start.sh:
#!/bin/bash
set -e
# How to apply migrations
dotnet ef database update
# I would like to run sql file at here"
psql -h postgres --username postgres -d POSTGRES_USER -a -f /app/static.sql
# Start web app
echo "Starting web app"
dotnet run
How can I do that? Thanks advanced.
I have just found a solution for this. I missed postgresql-client. We will be need to install postgresql-client as using psql to run the sql script from Dockerfile.
So Dockerfile should be changed:
# TODO use official docker image
FROM microsoft/dotnet:1.1.0-sdk-projectjson
# Install .NET CLI dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \
automake \
bzip2 \
file \
g++ \
gcc \
imagemagick \
libbz2-dev \
libc6-dev \
libcurl4-openssl-dev \
libdb-dev \
libevent-dev \
libffi-dev \
libgdbm-dev \
libgeoip-dev \
libglib2.0-dev \
libjpeg-dev \
libkrb5-dev \
liblzma-dev \
libmagickcore-dev \
libmagickwand-dev \
libmysqlclient-dev \
libncurses-dev \
libpng-dev \
libpq-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libtool \
libwebp-dev \
libxml2-dev \
libxslt-dev \
libyaml-dev \
make \
patch \
xz-utils \
zlib1g-dev \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
# Install netcat so that we can ping the database server until it
RUN apt-get update -qq \
&& apt-get install -y netcat \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV ASPNETCORE_URLS="http://*:5000"
ENV ASPNETCORE_ENVIRONMENT="Development"
ENV DB_HOSTNAME="posgres"
# Copy files to app directory
COPY . /app
# Set working directory
WORKDIR /app
# Restore NuGet packages
RUN ["dotnet", "restore"]
# Build app
RUN ["dotnet", "build"]
#dotnet ef migrations add InitialCreate
RUN ["dotnet", "ef", "migrations", "add", "InitialCreate"]
# Open up port
EXPOSE 5000
CMD chmod +x ./docker-start.sh
CMD bash ./docker-start.sh
Thanks.