Configure and enable docker user namespace so root files in containers can be edited by current user in host and vice versa.
See https://docs.docker.com/engine/security/userns-remap/
Create the /etc/docker/daemon.json file to enable namespace remapping for the current user
{
"userns-remap": "my-username"
}
In the /etc/subuid file create a mapping between the unprivileged user in host and root user in containers:
my-username:my-UID:1
In the /etc/subgid file create a mapping between the unprivileged group in host and root group in containers:
my-username:my-GID:1
$ cd /path/to/project
$ git clone --depth 1 https://github.com/pyd/docker-symfony-fpm-postgresql.git .
- /path/to/project/docker/.env file: set GIT_USER_NAME and GIT_USER_EMAIL
- /path/to/project/docker/php/conf.d/xdebug.ini: customize config, like mode, log, idekey...
$ cd /path/to/project/docker
$ docker-compose up -d
$ sudo chmod -R 777 /path/to/project/pgadmin-data
$ docker-compose exec php sh
# composer create-project symfony/skeleton .
# git init
# git add .
# git commit -m "create symfony project"
symfony app URL: http://localhost:8080
pgadmin app URL: http://localhost:8181
According to https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html, this directory should be owned by 5050:5050
but this does not prevent an access denied on sessions/ subdirectory when trying to log in. Chmod 777 solved this.
Use variables defined in the /path/to/project/docker/.env file.
By default "host=db dbname=postgres user=postgres password=superuser_password" as DSN.
Note host=db. Internally, docker will replace 'db' with the IP of the php container.
Same DSN can be used in the symfony app and in pgadmin.
Comment code in /path/to/project/app/public/index.php and paste the code bellow.
if (!$connection = pg_connect ("host=db dbname=postgres user=postgres password=superuser_password")) {
$error = error_get_last();
echo "DB connection failed: ". $error['message']. "\n";
} else {
echo "DB connection succeeded.\n";
}
Remove pyd_symfony_* images
$ docker-compose down --rmi 'local'
or force docker to rebuild
$ docker-compose up -d --build