I have a little bit problem with install pdo_mysql into my docker container.
In Symfony I got this error:
PDOException PDOException DriverException
HTTP 500 Internal Server Error
An exception occurred in driver: could not find driver
Symfony - config.yml
doctrine:
dbal:
driver: pdo_mysql
Dockerfile
FROM phpdockerio/php7-fpm:latest
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install vim mc apt-utils \
&& php7-pdo_mysql php7-pdo \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
/usr/share/doc/*
WORKDIR "/var/www/project"
docker-compose.yml
version: "3.1"
services:
mysql:
image: mariadb
container_name: project-mariadb
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: project-pma
restart: always
links:
- mysql
ports:
- 8183:80
environment:
PMA_HOST: mysql
PMA_USER: root
PMA_PASSWORD: root
webserver:
image: nginx:alpine
container_name: project-websrv
working_dir: /var/www/project
volumes:
- ../../Sources/project/trunk/src/:/var/www/project
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
links:
- php-fpm
php-fpm:
build: phpdocker/php-fpm
container_name: project-php
working_dir: /var/www/project
volumes:
- ../../Sources/project/trunk/src/:/var/www/project
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-
overrides.ini
links:
- mysql
docker-compose ps
d:\Work\DockerContainers\project>docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
project -mariadb docker-entrypoint.sh mysqld Up 3306/tcp
project -php /bin/sh -c /usr/bin/php-fpm Up 9000/tcp
project -pma /run.sh phpmyadmin Up 0.0.0.0:8183->80/tcp
project -websrv nginx -g daemon off; Up 0.0.0.0:8080->80/tcp
d:\Work\DockerContainers\project>
I have this linux version:
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
I tried to change the package names for pdo_mysql in Dockerfile what I found on the forums, I tried installing through apt-get install directly in the container, but nothing helped I always get the same message:
/bin/sh: 1: docker-php-ext-install: not found (docker-compose build)
E: Unable to locate package php7-mysql (pdo_mysql etc.) (root in docker container)
php-ini-overrides.ini
upload_max_filesize = 100M
post_max_size = 108M
extension=pdo.so
extension=pdo_mysql.so
I don´t know if is this problem in Symfony configuration or problem with docker
Can you help me, please?
Thanks a lot
Related
I want to set up a development environment for WordPress which supports IDE debugging through Xdebug and is contained in a docker container.
I'm working from WSL2 / Ubuntu 18.04
I'm using a MySQL official image
I'm using a WordPress image built on top of the WordPress official image with Xdebug installed through PECL
I'm copying configuration files for php.ini and xdebug.ini from a local folder
After launching my container I'm attaching a VSCode instance to the container by using ms Remote Containers extensions
I'm installing the official PHP debug VSCode extension from the Xdebug team in the attached instance of VSCode
I'm automatically generating a launch.json file for PHP
I'm setting a breakpoint and launching the debugger by pressing F5
What happens is that the debugger starts, offering me to open a browser at the port I set for Xdebug (9003), but the page doesn't load, the breakpoint isn't reached and the debugger tab in VSCode shows several errors such as: Failed initializing connection 1: connection closed (on close)
I tried other slightly different methods such as having the dockerfile build Xdebug from source as well as other setups for the ini files from tutorials found on the internet, but the end result is always the same.
If I try to run xdebug_info() through the browser I get a normal output, if I try to run the file from console I get this error:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
which is in line with similar errors I get in the docker-compile output.
I tried forwarding the 9003 port with docker-compile, but the behavior didn't change.
These are my docker and config files:
docker-compose.yml
version: "3.6"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
build:
context: ./wordpress
dockerfile: Dockerfile
volumes:
- wordpress_data:/var/www/html
ports:
- "8080:80"
# - "9003:9003"
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
wordpress/Dockerfile
FROM wordpress:latest
RUN apt-get update && \
apt-get -y install git
# RUN git config --global url."https://github".insteadOf git://github
RUN pecl install xdebug
COPY ../config/ /
RUN docker-php-ext-enable xdebug
wordpress/config/usr/local/etc/php/php.ini (edited from php.ini-development)
...
[Xdebug]
xdebug.remote_autostart = 1
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.show_local_vars = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
(Since it seems this isn't being tracked I also tried making a symbolic link from php.ini-development to php.ini from the container console, then adding the variables there.)
wordpress/config/usr/local/etc/php/conf.d/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.mode=develop,debug,trace,profile,coverage
xdebug.start_with_request = yes
xdebug.discover_client_host = 0
xdebug.remote_connect_back = 1
xdebug.client_port = 9003
xdebug.client_host='host.docker.internal'
xdebug.idekey=VSCODE
I know I'm really close on this, but I can't get the last part
working. I'm almost positive it has to do with the WordPress
container and the PHP container needing to be the same directory? So
PHP can process files in that directory? I have been working on this
for a week and a half and I'm breaking down, asking for help.
I can most of this working and different combinations - but not this
particular combination.
What I'm trying to do is have separate containers for MySQL (and
share the database) nginx-proxy WordPress using Nginx (each site with
their own WordPress container) PHP 7
I've gotten this working with WordPress using Apache, but that's not
what I want.
I have done a lot of reading and a lot of testing and did find that I
was originally missing VIRTUAL_PROTO=fastcgi. I see the configs that
populate in the nginx-proxy container...they seem right, but I think
my confusion has to do with the paths and the virtual environments.
I create docker network create nginx-proxy
These are the files and directories I have...
/home/tj/db/docker-compose.yml /home/tj/mysite.com
/home/tj/mysite.com/.env /home/tj/nginx-proxy/docker-compose.yml
/home/tj/db/docker-compose.yml
version: "3"
services:
db:
image: mysql:5.7
volumes:
- ../_shared/db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
container_name: db
networks:
- nginx-proxy
networks:
nginx-proxy:
external:
name: nginx-proxy
/home/tj/mysite.com/.env
MYSQL_SERVER_CONTAINER=db
VIRTUAL_HOST=mysite.com
DBIP="$(docker inspect ${MYSQL_SERVER_CONTAINER} | grep -i 'ipaddress' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])')"
EMAIL_ADDRESS=tj#mysite.com
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wordpress
/home/tj/mysite.com/docker-compose.yml
version: "3"
services:
wordpress:
image: wordpress:fpm
expose:
- 80
restart: always
environment:
VIRTUAL_HOST: ${VIRTUAL_HOST}
LETSENCRYPT_HOST: ${VIRTUAL_HOST}
LETSENCRYPT_EMAIL: ${EMAIL_ADDRESS}
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_USER}
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
VIRTUAL_PROTO: fastcgi
VIRTUAL_PORT: 3030
VIRTUAL_ROOT: /usr/share/nginx/html
container_name: ${VIRTUAL_HOST}
volumes:
- ../nginx-proxy/html:/usr/share/nginx/html:rw
networks:
default:
external:
name: nginx-proxy
/home/tj/nginx-proxy/docker-compose.yml
version: '3'
services:
nginx:
image: nginx:1.17.7
container_name: nginx-proxy
ports:
- 80:80
- 443:443
volumes:
- conf:/etc/nginx/conf.d:ro
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true
restart: always
dockergen:
image: jwilder/docker-gen:0.7.3
container_name: nginx-proxy-gen
depends_on:
- nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
restart: always
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
depends_on:
- nginx
- dockergen
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: always
php-fpm:
image: php:7-fpm
container_name: php
environment:
- VIRTUAL_HOST=docker.nevistechnology.com
- VIRTUAL_ROOT=/usr/share/nginx/html
- VIRTUAL_PORT=9000
- VIRTUAL_PROTO=fastcgi
restart: always
ports:
- 9000
volumes:
- ./html:/usr/share/nginx/html
volumes:
conf:
vhost:
html:
certs:
networks:
default:
external:
name: nginx-proxy
Now, what i was able to get working is if I use "wordpress:latest"
instead of "wordpress:fpm", but I don't want to use Nginx and
Apache...Apache uses a lot of memory and I have all of my old configs
and notes in Nginx, so I'd like to get this working.
I have some Dockerfile things I'm trying to figure out too - like
running commands, but let me see if you all can help me with this
first.
Another thing - this is more of a generic Linux issue, but over the
years I've never been able to figure it out and I just default to
using root, which I know is bad practice. So, I have my user "tj"
which I created like:
sudo useradd tj sudo usermod -aG sudo tj sudo usermod -aG docker tj
sudo usermod -aG www-data tj sudo g+w /home/tj -R *
For Docker, I started working out of my /home/tj directory. When I
try to go edit a file or upload, I get a permission issue. But if I
change directories and files from www-data:www-data to tj:www-data or
tj:tj, it works for me in SFTP or terminal, but then there are web
issues, like when I try to upload - www-data has permission issues on
the WordPress sid.
So, I know I'm late to the party here but I might have some answers so here goes nothing:
I eventually got that running and more, all in a swarm but I had to tweak the proxy quite a bit:
https://github.com/PiTiLeZarD/nginx-proxy
Something I had to wrap my mind around was that the fpm image runs php only! any assets or files has to be bound as a volume in the nginx-proxy and configured so nginx gets the files and not fpm. In my tweaked nginx-proxy I have added something about this in the templates:
{{ if (exists (printf "/etc/nginx/static_files/%s" $host)) }}
root {{ printf "/etc/nginx/static_files/%s" $host }};
{{ end }}
vhost.d/default: I added a section:
location / {
location ~ \.php$ {
try_files /dev/null #upstream;
}
try_files /assets/$uri $uri #upstream;
}
I tweaked everything to have a LOCATION_PATH=#upstream environment variable (I have many services so some still use the default "/")
vhost.d/default_location, I added the fastcgi config there:
index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
There's a lot to configure and keep track of, but hang on, it's possible to make it work.
Regarding the root/user issues, I run my php-fpm images as www-data:www-data (which is 1000:1000) I also make sure that 1000:1000 links to the admin user on the host, this way I don't end up with issues all the time.
fpm's www.conf has a user/group section where you can specify www-data/www-data and I build my images with a trick for users:
# add a NOPASSWD to sudo for www-data
RUN printf 'www-data ALL=(ALL:ALL) NOPASSWD: ALL' | tee /etc/sudoers.d/www-data
# bind www-data user and group from 33:33 to 1000:1000
RUN rmdir /var/www/html \
&& userdel -f www-data \
&& if getent group www-data ; then groupdel www-data; fi \
&& groupadd -g 1000 www-data \
&& useradd -l -u 1000 -g www-data -G sudo www-data \
&& install -d -m 0755 -o www-data -g www-data /home/www-data \
&& find / -group 33 -user 33 2>/dev/null || echo "/var/www" | xargs chown -R 1000:1000
This step will take care of switching everything from root:root to www-data:www-data. I also install sudo in my docker images, I used to not but I had issues which were really hard to fix without it.
Not sure if any of this helps, it's a little disjointed but then again, running this requires a lot of moving pieces to fit perfectly together ;)
I have gone through the documentation but running across issues as I'm launching the containers through docker-compose.
I'm using docker-compose because I have more than one containers that directly correlates to each csproj file within the location, also the docs refer to attributes using Dockerfile which itself adds another layer of complexity.
docker-compose.yml
version: '3'
services:
app1:
image: mcr.microsoft.com/dotnet/core/sdk:2.2
container_name: app1
restart: on-failure
working_dir: /service
command: bash -c "dotnet build && dotnet bin/Debug/netcoreapp2.2/App1.dll"
ports:
- 5001:5001
- 5000:5000
volumes:
- "./App1:/service"
app2:
image: mcr.microsoft.com/dotnet/core/sdk:2.2
container_name: app2
restart: on-failure
working_dir: /service
command: bash -c "dotnet build && dotnet bin/Debug/netcoreapp2.2/App2.dll"
ports:
- 5001:5001
- 5000:500
Project Structure
Microservice.sln
App1/App1.csproj
App2/App2.csproj
Issue
My IDE starts to complain as soon as I run the containers for all kinds of syntax errors, and a local build simply fails.
is there a way to be able to compile the app locally as well as in the docker?
Edit
I'm new to docker and I'm just trying to create a simple Symfony API. I ran docker-compose up -d which created these containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
071de3320346 willdurand/elk "/usr/bin/supervisor…" About a minute ago Up About a minute 0.0.0.0:81->80/tcp simple-api_elk_1
c24132f645be simple-api_nginx "nginx" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 443/tcp simple-api_nginx_1
37128a03b667 simple-api_php "php-fpm7 -F" About a minute ago Up About a minute 0.0.0.0:9000->9000/tcp simple-api_php_1
aa7738c59891 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp simple-api_db_1
I then took the id from the simple-api_php and ran
docker exec 37128a03b667 composer create-project symfony/website-skeleton symfony-api
It returns:
OCI runtime exec failed: open /tmp/runc-process126262263: permission denied: unknown
here is my docker-compose.travis.yml:
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
php:
build: ./php-fpm
expose:
- "9000"
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/var/logs
links:
- db
nginx:
build: ./nginx
ports:
- "80:80"
links:
- php
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- php
- nginx
Just don't have enough knowledge to troubleshoot this.
Thanks!!
You should edit your elk service.
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns <-------- remove this line
volumes_from:
- php
- nginx <-------- remove this line
Note: comments are marked with arrow <------
Also, if you still have the same issue - try to remove images and containers and then rebuild them.
// This command will remove all containers and images in your docker-compose.travis.yml file
$: docker-compose down
// Or you can remove container and images manually
$: docker rm container_name
$: docker rmi image_name
I try to build a web stack with docker using "php, mariadb, ngnix, composer"
I try to use only container from official repositories
following my docker-compose.yml
version: '2'
services:
nginx:
image: nginx
container_name: nginx
ports:
- "8000:80"
mariadb:
image: mariadb
container_name: mariadb
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_USER : root
MYSQL_ROOT_PASSWORD: root
php:
image: php:fpm
container_name: php
ports:
- "80:80"
volumes:
- ./php/:/var/www/html/
composer:
image: composer
container_name: composer
volumes_from:
- php
working_dir: /var/www/
volumes:
- ./composer2:/app
this docker-compose work correctly, but I don't understand why composer down quickly after 'docker-compose up -d'
PS:My first goal is to use this stack for symfony2 or silex
The composer container is ended imediatelly becuase it's not intended to run as a "daemon". In case you don't provide any command, the composer, simply said, has nothing to do. Anyways, if it has "something to do", then it executes it and ends.
You can use it through interactive shell like this:
docker run --rm --interactive --tty --volume $PWD:/app composer install
More examples are in the "Using" section here: https://hub.docker.com/_/composer/