I currently have a problem running my apache web-server successfully while using Docker...
Here is my docker file:
FROM fedora:27
# Container Owner
MAINTAINER nzhiti#gmail.com
# Update & install Apache & clean dnf
RUN dnf upgrade -y
RUN dnf install -y httpd
RUN dnf clean packages
RUN dnf install -y mod_ssl
# Configuring hosts
ADD ./hosts/hosts /etc/hosts
# Port
EXPOSE 443
# Starting httpd
ENTRYPOINT ["/usr/sbin/httpd"] & CMD ["-D", "FOREGROUND"]
No errors during building. But when I try to compose it, it never works, and the only message outputted is apache exiting with code 0
version: '3'
services:
php-apache:
image : httpd_fedora
ports:
- 443:443
volumes:
- ./Apache/www/:/var/www/html
- ./Apache/vhosts/:/etc/httpd/conf.d/
- ./Apache/SSLcert/:/etc/httpd/ssl/
- ./Apache/errorlogs/error.log:/var/log/httpd/error.log
tty: true
I'm out of ideas...
Thanks,
DRK
Try indenting tty: true so it's aligned with php_apache properties. Also copy the Dockerfile to the same directory of docker-compose.yml, and change image to build: ..
version: '3'
services:
php-apache:
build: .
ports:
- 443:443
volumes:
- ./Apache/www/:/var/www/html
- ./Apache/vhosts/:/etc/httpd/conf.d/
- ./Apache/SSLcert/:/etc/httpd/ssl/
- ./Apache/errorlogs/error.log:/var/log/httpd/error.log
tty: true
Related
I am trying to Dockerize my project (PHP MYSQL and PDO). Even though I added the scripts to install the extensions to my Dockerfile and every time I build it is installing them I am still getting: "Could not find driver". I checked in the phpinfo() and the driver is not there. I deleted all images and containers, built from scratch. Same result. Any ideas? In my docker file I have the following:
FROM php:7.4-apache
RUN apt-get update && apt-get upgrade -y
RUN docker-php-ext-install pdo pdo_mysql
EXPOSE 80
and my docker-compose.yaml file:
version: '3.3'
services:
web:
build:
context: ./php
dockerfile: Dockerfile
container_name: php74
depends_on:
- db
links:
- db
volumes:
- ./php:/var/www/html/
ports:
- 8008:80
db:
container_name: mysql8
command: --default-authentication-plugin=mysql_native_password
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: realDE
MYSQL_USER: khaldoun
MYSQL_PASSWORD: password
ports:
- 6033:3306
For the test I performed, I did the following:
Dockerfile -
FROM php:7.4-apache
RUN apt-get update && apt-get upgrade -y
RUN docker-php-ext-install pdo pdo_mysql
COPY $PWD/index.php /var/www/html
EXPOSE 80
# start Apache2 on image start
CMD ["/usr/sbin/apache2ctl","-DFOREGROUND"]
index.php
<?php
phpinfo();
?>
run command (I named the image pdo-test):
docker run --name=pdo-test -p 8080:80 -d pdo-test
Once the container was started I navigated to HTTP://localhost:8080/index.php and saw the PDO driver is loaded:
Please note the only difference between my Dockerfile and yours is that I copied a PHP page into /var/www/html and added a command that would start Apache when the container is run.
Things you should check:
is the volume you're mounting correct ./php:/var/www/html
since you have no command to execute Apache, confirm it is starting properly in the container. I tested both ways and it started each time, but you should bash into the container and make sure Apache is running as you expect.
EDIT I copied one of the php.ini files from the container
docker cp pdo-test:usr/local/etc/php/php.ini-production php.ini
and uncommented the PDO drivers:
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
Then I rebuilt the container, copying in the updated php.ini file:
FROM php:7.4-apache
RUN apt-get update && apt-get upgrade -y
RUN docker-php-ext-install pdo pdo_mysql
COPY $PWD/index.php /var/www/html
COPY $PWD/php.ini /usr/local/etc/php
EXPOSE 80
# start Apache2 on image start
# CMD ["/usr/sbin/apache2ctl","-DFOREGROUND"]
I can now see the php.ini file in phpinfo()
i'm new to docker and slimframework, i'm trying to make a docker file or docker-compose file that when i send to someone else they can run and have my sql db running with the tables already created i dont know if this is right but i get an error.
dockerfile
FROM php:7.1-apache
COPY apache2.conf /etc/apache2
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
this is my docker-compose
version: '2'
volumes:
logs:
driver: local
services:
db-mysql:
image: mysql:5
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: path
MYSQL_USER: root
MYSQL_PASSWORD: root
slim:
image: php:7-alpine
working_dir: /var/www
command: php -S 0.0.0.0:8080 -t public
environment:
docker: "true"
depends_on:
- db-mysql
ports:
- 80:8080
volumes:
- .:/var/www
- logs:/var/www/logs
I've created a PHP/Apache/MySQL development environment with Docker and would like to set variable that I can use with $_SERVER in PHP.
Usually I will configure something like that in my virtual host
SetEnv ENV "developement"
Is there a way to do it with my docker_compose.yml file ?
I'll try by using environment: - ENV=developement in my docker-compose file but it doesn't work.
Here is my Dockerfile
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
and my docker-compose.yml
version: '2'
services:
webserver:
build: ./docker/webserver
image: dev_web
ports:
- "80:80"
- "443:443"
volumes:
- /pathtodev/www:/var/www/html
links:
- db
environment:
- ENV=developement
db:
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=******
- MYSQL_DATABASE=db_dev
Consider the below Dockerfile
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
RUN echo 'PassEnv FIRST_NAME' > /etc/apache2/conf-enabled/expose-env.conf
RUN echo '<?php echo $_SERVER["FIRST_NAME"];' > /var/www/html/first.php && echo '<?php echo $_SERVER["LAST_NAME"];' > /var/www/html/last.php
Now run the container using
docker run -it -e FIRST_NAME=TARUN -e LAST_NAME=LALWANI -p 80:80 4ba2aa50347b
Testing
$ curl localhost/first.php
TARUN
$ curl localhost/last.php
$
As you can see the only FIRST_NAME can be accessed, because we exposed the same using PassEnv directive in our apache config insider the container
I know this is a old thread, however, another solution could also be that inside your docker compose, you need to remove the "-" in front of ENV and then instead of "=" it needs to be ":".
It will end up looking like this then:
version: '2'
services:
webserver:
build: ./docker/webserver
image: dev_web
ports:
- "80:80"
- "443:443"
volumes:
- /pathtodev/www:/var/www/html
links:
- db
environment:
ENV: developement
db:
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=******
- MYSQL_DATABASE=db_dev
At least it's working like that in version 3.
Hello guys im trying to setup an Dockerfile with ubuntu php7 , and Apache with workdir /app/web. phpmyadmin and mysql is already running but i dont get it how to setup the Dockerfile for ubuntu and php7 any suggestions? yeah i know there are lots of finished solutions on docker hub and git but i prefere to create my i own to know how it does work.
version: '2'
services:
#######################################
# PHP application Docker container
#######################################
app:
build:
context: .
dockerfile: Dockerfile
links:
- mysql
ports:
- "8000:80"
volumes:
#- ./app/:/app/
- ./:/docker/
volumes_from:
- storage
networks:
- php-network
#######################################
# MySQL server
#######################################
mysql:
build:
context: docker/mysql/
dockerfile: MySQL-5.7.Dockerfile
restart: always
volumes_from:
- storage
env_file:
- etc/environment.yml
networks:
- php-network
#######################################
# PHP MY ADMIN
#######################################
myphpadmin:
build:
context: docker/myphpadmin
dockerfile: Dockerfile
restart: always
links:
- mysql
ports:
- 8080:80
environment:
- PMA_HOST=mysql
- VIRTUAL_PORT=80
networks:
- php-network
storage:
build:
context: docker/storage/
volumes:
- /storage
networks:
php-network:
driver: bridge
Dockerfile
FROM ubuntu:latest
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl lynx-cur
# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
# 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 apache.
EXPOSE 80
# Copy this repo 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
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUND
Found this solution Had to include apache-config.conf
I trying to use Docker for my Symfony3 project I got it running but I get this error:
The LDAP PHP extension is not enabled.
It does sound right as I am using Ldap extension for my project. I have tried installing the Ldap extension using Dockerfile for my php image which seems to install it but still gives me this error.
Q1) How do I install required php extensions to my php image.
Q2) Once extension installed how do i enable it.
docker-compose.yml:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
project files
volumes_from:
- php
links:
- php
php:
image: php:5.6-fpm
volumes:
- ./project_code:/var/www/project
Dockerfile:
FROM php:5.6-fpm
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install php5-ldap -y
You need to point in your docker-compose.yml to the directory containing your Dockerfile. Then it builds your individual image based on this Dockerfile and links it as desired in docker-compose.
So you have to modify your docker-compose.yml. Lets assume you have stored your Dockerfile in the same directory as your docker-compose.yml file. Then you have to change it as follows:
version: '2' # <--
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
project files
volumes_from:
- php
links:
- php
php:
build: . # <--
volumes:
- ./project_code:/var/www/project
This builds your image as defined in the Dockerfile (currently your Dockerfile is ignored by your docker-compose.yml file). You then have to add to the Dockerfile how to enable your php module.
if you didn't find php.ini with php -i | grep php.ini
In docker, there are two php.ini files: php.ini-development and php.ini-production
https://docs.docker.com/samples/library/php/