I'm trying to transfere our current website that use symfony2 in a docker container.
The developpers that made the deployement script are gone from the company and i never developped with php.
When i build my image i'm running the same command as they use to deploy.
php5 -d memory_limit=-1 composer.phar self-update && php5 -d memory_limit=-1 composer.phar install --prefer-dist --no-interaction
But when it does work at every deployement it failed a building.
I've checked that my docker image got internet. it does.
I've copied configuration file and ssl from our production service.
The installed packaged are: nodejs php5-cli curl php5-curl php5-mcrypt php5-intl php5-gd mcrypt npm php5-gd php5-common php5-mysql
I use a tool from php-docker to install pdo_mysql: docker-php-ext-install pdo pdo_mysql
The error when building.
PHP Warning: PDO::__construct(): Cannot connect to MySQL by using SSL in /app/jolicone/app/cache/dev/appDevDebugProjectContainer.php on line 3863
PHP Warning: PDO::__construct(): [2002] (trying to connect via tcp://cleardb.com:port-cleardb) in /app/jolicone/app/cache/dev/appDevDebugProjectContainer.php on line 3863
[PDOException]
SQLSTATE[HY000] [2002]
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
The command '/bin/sh -c cd /app/jolicone && php5 -d memory_limit=-1 composer.phar self-update && php5 -d memory_limit=-1 composer.phar install --prefer-dist --no-interaction' returned a non-zero code: 1
Does someone have an idea about where that could come frome ? i've trying install another package php5-mysqlnd but this doesn't work either.
If you want a have an eye to the DockerFile
FROM php:5.6-apache
RUN apt-get update && apt-get upgrade -y && apt-get install -y apt-utils nodejs php5-cli curl php5-curl php5-mcrypt php5-intl php5-gd mcrypt npm php5-gd php5-common php5-mysqlnd
RUN docker-php-ext-install pdo pdo_mysql
# Linking nodejs binary to node alias
RUN ln -s /usr/bin/nodejs /usr/sbin/node
# Telling php about mcrypt extension
RUN sed -i '/memory_limit/c\memory_limit = -1' /etc/php5/cli/php.ini
RUN php5enmod gd mcrypt mysql pdo_mysql
COPY apache2/php.ini /usr/local/etc/php/
# Local Repository
RUN mkdir /app/
COPY jolicone/ /app/jolicone
############# Installing Composer #################
RUN cd /app/jolicone/ && php5 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN cd /app\/jolicone && php5 composer-setup.php
RUN cd /app/jolicone && php5 -r "unlink('composer-setup.php');"
# Copy Apache2 Configuration
COPY apache2/sites-enabled /etc/apache2/sites-enabled/
COPY apache2/file.pem apache2/file.crt apache2/file.key /etc/apache2/
COPY apache2/ssl /etc/apache2/ssl
RUN a2enmod rewrite headers && service apache2 restart
#Copy composer.json
RUN rm -f /app/jolicone/composer.json
COPY app/composer.json /app/jolicone/
# Copy config.yml
RUN rm -f /app/jolicone/app/config/config.yml
COPY app/config.yml /app/jolicone/app/config/config.yml
# Copy parameters.yml
RUN rm -f /app/jolicone/app/config/parameters.yml
COPY app/parameters.yml /app/jolicone/app/config/parameters.yml
## mise a jour du composer.phar -> OK
RUN cd /app/jolicone && php5 -d memory_limit=-1 composer.phar self-update && php5 -d memory_limit=-1 composer.phar install --prefer-dist --no-interaction
So i added the ca-certificates packages. and now the build is ok.
But when I run my image and try to connect to the website I got the same error.
vmtest:~/Docker$ cat log/*
- - [21/Jun/2016:10:29:00 +0000] "GET / HTTP/1.1" 503 261 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:47.0) Gecko/20100101 Firefox/47.0"
[Tue Jun 21 10:29:04.011586 2016] [:error] [pid 6] [client] PHP Warning: PDO::__construct(): Cannot connect to MySQL by using SSL in /path/file.php on line 1691
[Tue Jun 21 10:29:04.011648 2016] [:error] [pid 6] [client] PHP Warning: PDO::__construct(): [2002] (trying to connect via tcp://db:port) in /path/file.php on line 1691
[Tue Jun 21 10:29:04.011886 2016] [:error] [pid 6] [client] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] ' in /path/file.php:1691\nStack trace:\n#0 /path/file.php(1691): PDO->__construct('mysql:host=db...', '', '', Array)\n#1 /path/bootstrap.php.cache(2051): appProdProjectContainer->getPdoService()\n#2 /path/file.php(1891): Symfony\\Component\\DependencyInjection\\Container->get('pdo')\n#3 /path/bootstrap.php.cache(2051): appProdProjectContainer->getSession_Handler_PdoService()\n#4 /path/file.php(1903): Symfony\\Component\\DependencyInjection\\Container->get('session.handler...')\n#5 /path/bootstrap.php.cache(2051): appProdProjectContainer->getSession_Storage_NativeService()\n#6 /path/file.php(1887): Symfony\\Component\\DependencyInjection\\Container->get('session.storage...')\n#7 /app/jol in /path/file.php on line 1691
vmtest:~/Docker$
Related
i just have push my Symfony 5.4 application in my company server with Gitlab-ci and docker.
I have a Dokcerfile in the root avec my projet:
FROM php:7.4-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
COPY . /var/www/html/
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;
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# INSTALL COMPOSER
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
# INSTALL EXTENSION PHP
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
# INSTALL YARN
RUN apt-get update && apt-get install -y gnupg2
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn
RUN apt update
RUN chown -R www-data:www-data /var/www/html
RUN a2enmod rewrite
RUN service apache2 restart
And i have this job on my gitlab pipeline:
deploy_image:
stage: deploy
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- cd /srv/docker/stacks/r-panda
- docker network disconnect --force r-panda_default traefik_app
- /usr/local/bin/docker-compose down
- /usr/local/bin/docker-compose pull
- /usr/local/bin/docker-compose up -d
- docker network connect r-panda_default traefik_app
after_script:
- docker exec r-panda_app yarn install
- docker exec r-panda_app yarn run build
- ls -al
environment:
name: dev
url: $SERVER_URL
variables:
DATABASE_URL: $DATABASE_URL
tags:
- deploy
And there is my docker-compose.yaml on the server who run the contener with the application:
version: '3.9'
services:
r-panda_app:
container_name: r-panda_app
image: panda
environment:
- DATABASE_URL="mysql://db_user:db_pass#bbd_server:3306/panda_bdd"
restart: always
labels:
- traefik.enable=true
- traefik.http.routers.router-r-panda.rule=Host(`r-panda.fr`)
- traefik.http.routers.router-r-panda.tls.certresolver=myresolver
- traefik.http.routers.router-r-panda.tls=true
With this config i have the following error: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory
But if i change my config/packages/doctrine.yaml
This
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: '%env(resolve:DATABASE_URL)%'
To this:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: 'the real path for the DATABASE_URL'
Everything works
I don't know what to do, can someone help me
I'm setting up a Dockerfile where I can run my automated tests, and I'm having troubles with connecting to mysql database.
The Dockerfile depends on a prevoously built image and looks like this:
# Stage 0, assign argument as multistage image alias
ARG PHP_IMAGE
FROM ${PHP_IMAGE} as image
# Stage 1, start tests
FROM php:7.2-fpm
RUN curl -sS https://getcomposer.org/installer | php \
&& chmod +x composer.phar && mv composer.phar /usr/local/bin/composer
RUN apt-get update && apt-get install -y gnupg
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get install -yq nodejs build-essential \
git unzip \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
subversion \
&& curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install -j$(nproc) mysqli
RUN apt-get install -y mysql-server
RUN /etc/init.d/mysql start
RUN mysqladmin -u root -p status
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN npm install -g npm
COPY --from=image /var/www/html/ /var/www/html/
WORKDIR /var/www/html/
COPY scripts/develop.sh develop.sh
COPY scripts/docker-test.sh docker-test.sh
RUN ["/bin/bash", "-c", "bash develop.sh && bash docker-test.sh"]
I've added RUN mysqladmin -u root -p status to try to debug why connecting to mysql failed and I got
Enter password: mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
To run this I am running
docker build -t $TEST_DOCKER_NAME --build-arg PHP_IMAGE=$DOCKER_IMAGE_NAME_PHP -f Dockerfile.test .
The TEST_DOCKER_NAME and DOCKER_IMAGE_NAME_PHP are stored in an env file and read from there. The PHP image was built successfuly and I'm using it to copy the files from there to here so that I can run PHPUnit.
When I remove that RUN line my build fails when I'm trying to run a script that creates the database
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (99 "Cannot assign requested address")'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
What do I need to do in my Dockerfile to make it work?
Answer to your specific problem
This is a common mistake people make when using docker. When you use the RUN directive in docker you are running a command through to completion, capturing the filesystem changes and then exiting.
So when you have the lines
RUN /etc/init.d/mysql start
RUN mysqladmin -u root -p status
The first one is starting mysql. But then the changes are captured, the container is exited and then a new one is started to run the mysqladmin command. Therefore the mysql process is no longer running.
To avoid this you could combine them into a single line like
RUN /etc/init.d/mysql start && mysqladmin -u root -p status
However you will need to do this every time you want to use mysql. Such as in your develop.sh.
Wider answer
It is not recommended to run multiple processes within your container and it is also not recommended to use init.d or other system startup frameworks within your container.
You seem to be treating your container like a virtual machine and are having issues because containers are not VMs.
I recommend you explore running mysql in a separate container and then using a tool like docker-compose to start and and stop your containers.
I'm trying to run moodle phpunit on my gitlab ci server. Using gitlab-ci.yml file i'm creating a container with php 5.6 and mysql service.
# Services
services:
- mysql:latest
before_script:
- mysql -e 'CREATE DATABASE gitlab_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
I'm getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) and not sure how to proceed.
Tomasz this is my gitlab-ci.yml file you will need something like this:
# Select image from https://hub.docker.com/r/_/php/
image: php:7.0.0
services:
- mysql:5.7
variables:
# Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
MYSQL_DATABASE: symfony
MYSQL_ROOT_PASSWORD: qwerty
# Composer stores all downloaded packages in the vendor/ directory.
# Do not use the following if the vendor/ directory is commited to
# your git repository.
cache:
paths:
- vendor/
before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
- cp ci/parameters.yml app/config/parameters.yml
- composer install
test:app:
script:
- phpunit
And this is my docker_install.sh inside ci folder
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
apt-get install wget -yqq
apt-get install zip unzip -yqq
# Install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Install phpunit, the tool that we will use for testing
curl -o /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit
# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo pdo_mysql mbstring
So i have this Dockerfile:
FROM debian:squeeze
MAINTAINER Name < email : >
# Update the repository sources list
RUN apt-get update
# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 build-essential php5 mysql-server openssh-server libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur
# Enable apache mods.
RUN a2enmod php5
RUN a2enmod rewrite
# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
EXPOSE 80
# Copy site into place.
ADD www /var/www/site
# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
# start mysqld and apache
EXPOSE 3306
RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl -D FOREGROUND;/usr/sbin/sshd -D'
it builds up, no problem,MySQL and Apache start and work fine but the ssh won't work and i don't know why. openssh-server is installed.
i tried starting it up like this:
#startup.sh file
#/bin/bash
sshd
+
ADD ./startup.sh /opt/startup.sh
ENTRYPOINT ["/opt/startup.sh"]
and many other,i'm stuck.
What am i doing wrong?
you are starting apache in the foreground, hence the apachectl process will never give back the hand to the shell that started it and thus the /usr/sbin/sshd -D will never be called (unless you kill apache).
The following instruction will start both mysql and apache in the background and then sshd in the foreground:
CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl start;/usr/sbin/sshd -D'
While such a CMD statement is ok for tests I would advise using a different approach for running multiple processes in a single docker container:
supervisor
phusion/baseimage
Replace below lines of code in the docker file,
RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Using these codes
RUN apt-get install -y openssh-server
RUN echo 'root:password' |chpasswd
RUN mkdir -p /var/run/sshd
this works for me.
Note: Use ssh only for debugging purpose, it is not a good practice at all.
I have downloaded mysql-5.6.17-osx10.7-x86.tar.gz from here. Now I've got a folder full of MySQL-related files. Trouble is, I don't know what to do to install MySQL. I tried executing mysql_install_db, but the result was:
Last login: Sat May 24 10:45:08 on ttys000
host237-40-dynamic:~ michelegorini$ /Users/michelegorini/Downloads/mysql-5.6.17-osx10.7-x86/scripts/mysql_install_db ; exit;
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
logout
[Process completed]
So what do I do now?
Update:
Taking the answer into account, I tried something, with this result:
Last login: Sat May 24 10:45:08 on ttys000
host237-40-dynamic:Hakka_ michelegorini$ $ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
curl: (22) The requested URL returned error: 400
-bash: $: command not found
host237-40-dynamic:Hakka_ michelegorini$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" && brew install git &&
> brew update
curl: (22) The requested URL returned error: 400
-bash: brew: command not found
host237-40-dynamic:Hakka_ michelegorini$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" && brew install git && brew update && brew install mysql
curl: (22) The requested URL returned error: 400
-bash: brew: command not found
host237-40-dynamic:Hakka_ michelegorini$
What now?
The homebrew package manager takes away the pain in installing packages on your computer.
Here's how to install mysql on a mac
The command in one line:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" && brew install git && brew update && brew install mysql