MongoDB & Symfony 6: Doctrine/mongodb-orm could not installed (Docker) - mongodb

I'm trying to connect my Symfony 6 project with the MongoDB database on the Docker environment but when I launch the following command
composer require doctrine/mongodb-odm
This message appears
Your requirements could not be resolved to an installable set of packages.
Problem 1
- doctrine/mongodb-odm[1.0.0, ..., 1.0.8] require symfony/console ~2.3|~3.0 -> found symfony/console[v2.3.0, ..., v2.8.52, v3.0.0, ..., v3.4.47] but it conflicts with your root composer.json require (6.1.*).
- doctrine/mongodb-odm[1.1.0, ..., 1.3.7] require php ^5.6 || ^7.0 -> your php version (8.1.12) does not satisfy that requirement.
- Root composer.json requires doctrine/mongodb-odm ^1.0 -> satisfiable by doctrine/mongodb-odm[1.0.0, ..., 1.3.7].
You can also try re-running composer require with an explicit version constraint, e.g. "composer require doctrine/mongodb-odm:*" to figure out if any version is installable, or "composer require doctrine/mongodb-odm:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
my docker-compose file
version: '3.8'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:example#mongo:27017/
www:
build: php
container_name: www-docker-env
ports:
- '80:80'
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www
-
type: 'bind'
source: '../project/'
target: '/var/www/'
consistency: 'delegated'
restart: always
networks:
- dev
networks:
dev:
volumes:
mongo-data:
the Dockerfile file
FROM php:8.1-apache
ARG user
ARG uid
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
RUN apt-get update \
&& apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev \
&& apt install -y unzip;
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF_8" >> /etc/locale.gen && \
locale-gen
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/
USER $user
Is there any point that I did not notice in the above files, and is there any solution to the following problem?

If you want to use PHP 8.1, upgrade mongodb-odm to version 2.3. This is the first version to support PHP 8 as outlined in this statement:
We have released a new minor version 2.3 of Doctrine MongoDB ODM, the first version with support for using PHP 8 Attributes as a new driver for mapping documents and several other changes. See all changes and contributors in the Changelog on GitHub.
Otherwise, downgrade to PHP 7.0 as indicated in the error message.

Related

Update PostgreSQL version to 13 in TravisCI

I have some issues with the TravisCI platform when I try to test the code when Pull Requesting some changes. It works fine so far, but now I get this warning in the build-run log when I run the travis_apt_get_update command:
The PostgreSQL version 9.4 is obsolete, but the server or client packages
are still installed. Please install the latest packages (postgresql-13 and
postgresql-client-13) and upgrade the existing clusters with
pg_upgradecluster (see manpage).
I have added the postgresql-13 and postgresql-client-13 packages, here is the .travis.yml file:
language: perl
perl:
- "5.30"
dist: xenial
env:
- HOST_URL="localhost"
cache:
directories:
- $HOME/path/to/local
services:
- postgresql
addons:
postgresql: 13
apt:
packages:
- postgresql-13
- postgresql-client-13
- libpq-dev
- build-essential
- libssl-dev
- zlib1g-dev
- clang-tidy
env:
global:
- PGPORT=5433
before_install:
- wget http://mirrors.kernel.org/ubuntu/pool/universe/a/astyle/astyle_3.1-1ubuntu2_amd64.deb
- sudo dpkg -i astyle_3.1-1ubuntu2_amd64.deb
- sudo chmod -R 777 /var/log/
Now, in the log it says that I have to upgrade the clusters with pg_upgradecluster, but I really don't know what that means.
This example (.travis.yml) shows how to run Postgres13 within your Ubuntu jobs. You can configure/add additional configuration as your setup and see if that helps.
---
dist: focal
language: ruby
addons:
postgresql: '13'
apt:
packages:
- postgresql-13
env:
global:
- PGUSER=postgres
- PGPORT=5432
- PGHOST=localhost
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- postgres --version
script:
- psql -c 'create database travis_ci_test;' -U postgres
Let me know if you have further questions.
Thanks.

Running cron job inside container with python code and postgres database

I am new into docker, and I have created a container with python + postgres, which runs a python script that collects some data and writes it down on the SQL database. Now, I need to set this job to run each day. And then the nightmare started. I did not manage to create a separate container for this job, so I tried to create a file and copy it into the container via DockerFile (see this one down). I did not manage to run cron as entry-point for the container because then my database was not mounted. So, I create the container, access it, give full permissions to /var/www/html, and create the database table. And then I run cron. No erro, but nothing happens, no log is written on /var/log/cron.log. Here my files:
Dockerfile:
FROM postgres:latest
USER root
RUN apt-get update && apt-get install -y python3 python3-pip
RUN apt-get -y install cron nano
RUN apt-get -y install postgresql-server-dev-10 gcc python3-dev musl-dev
RUN pip3 install psycopg2 \
bs4 \
requests \
pytz
COPY temp-alerts-cron /etc/cron.d/temp-alerts-cron
RUN chmod 0777 /etc/cron.d/temp-alerts-cron
RUN chmod gu+rw /var/run/
RUN chmod gu+s /usr/sbin/cron
RUN touch /var/log/cron.log
RUN chmod 0777 /var/log/cron.log
RUN crontab /etc/cron.d/temp-alerts-cron
USER postgres
EXPOSE 5432
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
The temp-alers-cron:
20 13 * * * root /var/www/html/run.sh >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job
And the called script:
echo 'inside thingy' >> /var/log/cron.log 2>&1
python3 /var/www/html/nuria_main.py
In case it is needed, here the docker-compose.yml:
services:
postgres:
container_name: 'temp-postgres'
build: # build the image from Dockerfile
context: ${PWD}
volumes: # bind mount volume for Postgres data
- pg-data:/var/lib/postgresql/data
- ./python-app:/var/www/html
restart: unless-stopped
environment:
- POSTGRES_USR=xxadmin
- POSTGRES_DB=tempdb
- POSTGRES_PASSWORD=secret
expose:
- "5432"
networks:
kong:
networks:
kong:
external:
name: kong_net
volumes:
pg-data:
Hope somebody knows what I am doing wrong. I do not get any log or error, so i am lost.
Thanks!

No existing local cluster is suitable error using pg_dump in docker

In my docker project with postgres 9.6 I need to add support for uploading of big sql dumps.
I added pg_dump by adding in my web/Dockerfile.yml file line:
postgresql-client-common \
as it contains pg_dump.
After building the app I enter bash and
# uname -a
Linux ff5146f21dbd 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 GNU/Linux
root#ff5146f21dbd:/var/www/lprods_docker_root# pg_dump
Warning: No existing local cluster is suitable as a default target. Please see man pg_wrapper(1) how to specify one.
Error: You must install at least one postgresql-client-<version> package
root#ff5146f21dbd:/var/www/lprods_docker_root# locate -i pg_dump
Last command outputs nothing
web/Dockerfile.yml contains :
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y \
python \
libfreetype6-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
nano \
git-core \
curl \
build-essential \
openssl \
libssl-dev \
libgmp-dev \
libldap2-dev \
libpq-dev \
netcat \
postgresql-client-common \
locate \
&& git clone https://github.com/nodejs/node.git \
&& cd node \
&& git checkout v12.0.0 \
&& ./configure \
&& make \
&& make install
RUN npm install cross-env
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd pgsql pdo_pgsql zip gmp bcmath pcntl ldap sysvmsg exif \
&& a2enmod rewrite
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf
and docker-compose.yml:
version: '3'
services:
web:
build:
context: ./web # directory of web/Dockerfile.yml
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER=#1000
# - APACHE_RUN_USER=www-data
container_name: lprods_web
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- "8086:80"
working_dir: ${APP_PTH_CONTAINER}
db:
image: postgres:9.6.10-alpine
container_name: lprods_db
ports:
- '5433:5432'
restart: always
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: '1'
POSTGRES_DB: 'wprods'
volumes:
- ./init:/docker-entrypoint-initdb.d/
phppgadmin:
image: dockage/phppgadmin:latest
environment:
- PHP_PG_ADMIN_SERVER_HOST=db
- PHP_PG_ADMIN_SERVER_PORT=5432
- PHP_PG_ADMIN_SERVER_DEFAULT_DB=postgres
container_name: lprods_phppgadmin
restart: always
ports:
- "8087:80"
- "443:443"
links:
- db
composer:
image: composer:1.6
container_name: lprods_composer
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install --ignore-platform-reqs
Why error and how to fix it?
MODIFIED :
I have
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
But checking version I got error :
# /usr/bin/pg_dump -v
Warning: No existing local cluster is suitable as a default target. Please see man pg_wrapper(1) how to specify one.
Error: You must install at least one postgresql-client-<version> package
The same error I got when running psql command(actually I need it):
/usr/bin/psql -h localhost -d wprods -U postgres -W -f "/var/www/lprods_docker_root/wprods_2017_10_23.sql"
Error: You must install at least one postgresql-client-<version> package
What is wrong with my configuration ?
MODIFIED 2:
In my docker-compose.yml I have :
db:
image: postgres:9.6.10-alpine
...
volumes:
- ./init:/docker-entrypoint-initdb.d/
Is it?
command :
locate -i postgresql.conf
outputs nothing
find /usr -name "postgresql.conf"
Also outputs nothing.
Also I have :
# ps -ef | grep postgres
root 28 21 0 08:40 pts/0 00:00:00 grep postgres
What did I miss ?
postgresql-client-common is a Ubuntu-specific package of scripts that allows users to work with multiple versions of Postgres (or multiple database clusters). It provies several scripts and symlinks that essentially override the functions of "real" postgres utilities (like pg_dump):
root#foo:/usr/bin# ls -al | grep pg_dump
lrwxrwxrwx 1 root root 37 Feb 8 2018 pg_dump -> ../share/postgresql-common/pg_wrapper
lrwxrwxrwx 1 root root 37 Feb 8 2018 pg_dumpall -> ../share/postgresql-common/pg_wrapper
You may need to also install postgresql-client-10 to make pg_dump work.
Note also that you have only installed the client tools. If you need to get a fully-functional PostgreSQL database up and running, I believe you will also need to install the postgresql-10 package

Dockerfile builds on linux/mac host OS, but not on Windows 10

I have the following Dockerfile for a django app:
FROM python:3.6
RUN mkdir /server
WORKDIR /server
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
libsqlite3-dev
RUN pip install -U pip setuptools
RUN pip install --upgrade pip
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
WORKDIR /server/django
ENTRYPOINT ["/bin/bash", "../docker-entrypoint-server"]
relevant docker-compose related to it:
version: '3'
services:
server:
build: .
container_name: server
environment:
SERVER_ENV: ${SERVER_ENV}
DB_AUTH_SOURCE: ${DB_AUTH_SOURCE}
DB_NAME: ${DB_NAME}
DB_HOST: ${DB_HOST}
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
networks:
- app
ports:
- 8081:8000
volumes:
- .:/server
command: /bin/bash
tty: true
stdin_open: true
they work like a charm on linux/mac, but not on Windows 10. When the build reaches the COPY instruction, all it copies are the directory and only the first nested directory within it with no content attached to it.
tried to check for the shared C:\ option on docker, didnt work.
tried on powershell with admin rights and nothing.
What could be the possible causes? Why it works on two host OS and not on Win 10?
edit 1: versions
Windows: Windows 10 Education, 1803
Linux: Ubuntu 18.03 LTS
Mac: High Sierra 10.03
Docker: latest version on all OSs
edit 2: the solution
Turns out that unsharing and sharing, pointed out by JDPeckham, revealed the problem: a firewall misconfig caused by an antivirus that was controlling these configs.
This article: https://success.docker.com/article/error-a-firewall-is-blocking-file-sharing-between-windows-and-the-containers is very helpful for troubleshooting those.

pg_dump server and pg_dump version mismatch in docker

When I run the command psql --version within the railsApp container, I get 9.4.12 and when I run the same within the postgres container, I get 9.6.2. How can I get the versions to match?
I am getting the following error when I try to do a migration on Rails App which does a pg_dump sql import.
pg_dump: server version: 9.6.2; pg_dump version: 9.4.12
pg_dump: aborting because of server version mismatch
rails aborted!
Here's my Docker-compose.yml file:
version: "2.1"
services:
railsApp:
build:
context: ./
ports:
- "3000:3000"
links:
- postgres
volumes:
- .:/app
postgres:
image: postgres:9.6
ports:
- "5432:5432"
volumes:
- ./.postgres:/var/lib/postgresql
The Dockerfile:
FROM ruby:2.3.3
# setup /app as our working directory
RUN mkdir /app
WORKDIR /app
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# Install base dependencies
FROM ruby:2.3.3
# setup /app as our working directory
RUN mkdir /app
WORKDIR /app
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
python \
rsync \
software-properties-common \
wget \
postgresql-client \
graphicsmagick \
&& rm -rf /var/lib/apt/lists/*
# Install node and npm with nvm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION v7.2.1
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION
ENV PATH $NODE_PATH/bin:./node_modules/.bin:$PATH
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# Install our ruby dependencies
ADD Gemfile Gemfile.lock /app/
RUN bundle install
# copy the rest of our code over
ADD . /app
ENV RAILS_ENV development
ENV SECRET_KEY_BASE a6bdc5f788624f00b68ff82456d94bf81bb50c2e114b2be19af2e6a9b76f9307b11d05af4093395b0471c4141b3cd638356f888e90080f8ae60710f992beba8f
# Expose port 3000 to the Docker host, so we can access it from the outside.
EXPOSE 3000
# Set the default command to run our server on port 3000
CMD ["rails", "server", "-p", "3000", "-b", "0.0.0.0"]
The same issue for me, I used an alternative way to take a dump,
First I access the terminal and run the pd_dump inside docker and copied the file from docker to host.
Below are the commands
docker exec -it <container-id> /bin/bash # accessing docker terminal
pg_dump > ~/dump # taking dump inside the docker
docker cp <container-id>:/root/dump ~/dump #copying the dump files to host
Hope the above solution helps.
The easiest approach is to use the correct postgres version in the docker-compose. Change:
postgres:
image: postgres:9.6
To:
postgres:
image: postgres:9.4.2
All available versions here.