hi how are you guys i have 2 docker-compose file but both files are not run properly i face this
enter image description here
error please tell me any body how to fix it i give u a compose file content
(COMPOSE FILE 1)
db:
build: ./mysql
volumes:
- /opt/containers/personal/mysql:/var/lib/mysql
web:
build: ./web
ports:
- 80:80
volumes:
- /opt/containers/personal/php:/var/www/html
links:
- db:db
(COMPOSE FILE 2)
version: "3"
services:
nginx:
build: ./nginx
ports:
- 80:80
- 443:443
volumes:
- /opt/containers/personal/nginx/certs:/certs
depends_on:
- web
networks:
- webdbnet
web:
build: ./web
volumes:
# Example of host volume mounted in container
# - /opt/containers/personal/php:/var/www/html
# Example of docker volume mounted in container
- web-data:/var/www/html
networks:
- webdbnet
db:
# build: ./mysql
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- /opt/containers/personal/mysql:/var/lib/mysql
networks:
- webdbnet
networks:
webdbnet:
volumes:
web-data:
(AND THIS IS MY BUILD DOCKER FILE CONTENT)
FROM php:7-apache
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
&& a2enmod rewrite expires \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-install gd mysqli opcache iconv \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
&& docker-php-ext-enable mcrypt mysqli
COPY index.html /var/www/html/
COPY index.php /var/www/html/
Sorry for my bad english
It looks like you are running the wrong version of PHP for mcrypt.
Try replacing
FROM php:7-apache
with
FROM php:7.2.14-apache-stretch
In your build file.
php:7-apache is taking you to the latest version, which is 7.3.1 and mcrypt seems to want 7.2.*
When you use official image for php and for this example try to install pecl install mcrypt-1.0.1 after that command you'll need to add this line to
RUN pecl install mcrypt
RUN echo "extension=mcrypt.so" >> /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
Only extension installed via docker-php-ext-install are not required to enable with *.so file
I hope this helps..
Related
I use the Docker environment with the Symfony framework. I created my own Dockerfile and my own docker-compose.yml file.
The problem is that the 'compose install' command does not run when I run the 'docker compose up' command.
Here is the code of my dockerfile :
ARG PHP_VERSION=8.1
FROM php:${PHP_VERSION}-fpm
RUN apt-get update && apt-get install -y
# Install modules
RUN apt-get install -y --no-install-recommends \
git \
zlib1g-dev \
libxml2-dev \
libzip-dev \
libpq-dev \
nano \
&& docker-php-ext-install \
zip \
intl \
pdo \
mysqli \
pdo_mysql \
opcache
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
# Install Symfony CLI
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
# Copy the application files
COPY . /var/www/html
# Install dependencies from composer.json
RUN composer install
# Set the default directory inside the container
WORKDIR /var/www/html
Here is the code of my yml file:
version: '3.8'
networks:
myapp:
services:
db:
container_name: ${APP_NAME}-db
image: 'mariadb:latest'
restart: always
ports:
- 3306:3306
volumes:
- './.docker/mysql:/var/lib/mysql'
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASS}
MYSQL_DATABASE: ${MYSQL_DB}
networks:
- myapp
php:
container_name: ${APP_NAME}-php
build: ./docker/php
volumes:
- './:/var/www/html'
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
depends_on:
- db
networks:
- myapp
nginx:
container_name: ${APP_NAME}-nginx
image: 'nginx:latest'
ports:
- 8080:80
#- 8443:443 # if https config
expose:
- 80
volumes:
- ./:/var/www/html
- ./docker/nginx/conf.d:/etc/nginx/conf.d
depends_on:
- php
networks:
- myapp
phpmyadmin:
image: 'phpmyadmin/phpmyadmin:latest'
container_name: ${APP_NAME}-phpmyadmin
ports:
- 8000:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS}
networks:
- myapp
Do you know where the problem is? I copy well the root files (where is my composer.json file) to the container folder (/var/www/html). My files are well present when I do the command 'docker-compose exec php /bin/bash' then 'ls'.
I have the following structure:
- MY-PROJECT
> docker/
> nginx/
> php
> Dockerfile
.env
composer.json
docker-compose.yml
I tried several methods, including moving the commands into the file or putting the 'compose install' command in the .yml file, but I don't think this is the solution.
I would suggest that you move your Dockerfile to the root directory of your project and set the context to .
php:
container_name: ${APP_NAME}-php
build: .
volumes:
- './:/var/www/html'
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
depends_on:
- db
networks:
- myapp
You need also to change some order inside your Dockerfile and for Symfony cli you need to change it:
RUN mv /root/.symfony5/bin/symfony /usr/local/bin/symfony
Last, if you are new on this i would suggest that you use the documentation from Symfony:
https://symfony.com/doc/current/setup/docker.html
You can then adapt it on your need and add phpMyAdmin etc...
I created a docker-compose.yml file with the code below :
version: "3.8"
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
container_name: docker_database
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- dev
phpmyadmin:
image: phpmyadmin:latest
container_name: docker_phpmyadmin
restart: always
depends_on:
- db
ports:
- 8081:80
environment:
PMA_HOST: db
networks:
- dev
prestashop:
build: php
container_name: docker_prestashop
ports:
- 8080:80
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www/html
restart: always
networks:
- dev
networks:
dev:
volumes:
db-data:
And also this Dockerfile :
FROM php:7.4-apache
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;
RUN echo "en_US.UTF8 UTF8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
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
RUN a2enmod rewrite && service apache2 restart
The goal is to create a prestashop environnement however I'm struggling with a Error 500 when trying to install the prestashop. I've read that it has something to do with file permissions. Some of the folders are accessible but I don't know why some of them like the config folder is in read-only. I've created a volume that I share with container and host but I think I did something wrong on the configuration.
Even when I run a chmod 770 <some-file> I can access it but when I'm trying to change something in it I get this error :
Cannot save /home/benju/Bureau/docker/config/defines.inc.php.
Unable to create a backup file (defines.inc.php~).
The file left unchanged.
How could I access them with the same permission as the container on the host computer ?
You could use the use the same user and group with the docker run parameter, --user "$(id -u):$(id -g)"
with this the container can still give you an error, while bash on the container won't, but other applications can, because the user and group need to be created, so in the docker file,
ARG USER_ID
ARG GROUP_ID
RUN addgroup --gid $GROUP_ID user
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
USER user
Then the file permissions which would be set by the container will on the volume will be the same as the host setting the file permissions.
More information on the following webpage,
https://vsupalov.com/docker-shared-permissions/
Here is what I've done and it worked (not sure if this is a good practice)
chown -R <hostuser>:<hostuser> <project root>
i'm new in DevOps tried to deploying Laravel app (from my bootcamp source code) to Kubernetes in my local machine (CentOS 7), i have problem when convert my docker-compose.yml with Kompose especially in volume mount. Can you tell me how to solve this problem? I have tried troubleshoot but not succeeded.
Here is my docker-compose.yml file:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: nightraven
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
and this is Dockerfile i create for Laravel app:
FROM php:7.2-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
And this is the error:
https://i.stack.imgur.com/LtKka.png
it's said
FATA Error while deploying application: k.Transform failed: Unable to
build Docker image for service app: Unable to create a tarball:
archive/tar: write too long
I am trying to learn Docker. I have installed Docker Desktop on my Windows10 Pro computer.
I started with getting a PHP, MySQL website up and running using Docker.
My docker-compose.yml looks like
version: "3.8"
services:
www:
build: .
ports:
- "80:80"
volumes:
- ./www:/var/www/html
links:
- db
networks:
- default
db:
image: mysql:8.0
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- ./conf:/etc/mysql/conf.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
and the DockerFile looks like
FROM php:7.3-apache
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y wget \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
I have a www folder with an index.php.
When I run
docker-compose up -d
I have the PHP, mySQL site up and running correctly and I can access the index.php with expected results.
So far so good.
Now, I want to change the Dockerfile to setup a php forum website (phpbb) - so I have updated my Dockerfile as follows:
FROM php:7.3-apache
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y wget \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
WORKDIR /var/www/html
RUN wget https://download.phpbb.com/pub/release/3.3/3.3.0/phpBB-3.3.0.tar.bz2 \
&& tar -xvjf phpBB-3.3.0.tar.bz2
&& ls -l
When I run
docker-compose build --no-cache
I can see the expected results - i.e, the "ls" command shows all the expected phpBB files in /var/www/html
However, when I run
docker-compose up -d
My container only has the index.php in the /var/www/html (the index.php from the www folder). None of the phpBB files are there.
What am I doing wrong?
The files are there but you are hiding them by your bind mount.
You are bind mounting ./www into the same directory (/var/www/html) which will hide its contents.
here:
www:
...
volumes:
- ./www:/var/www/html
When you are building the image, you correctly see the files but once you run docker-compose the bind mount is created and it hides those files.
I'm trying to contain our cakephp 3 app. I'm also trying to use phpmyadmin image and connect it to mysql image but when I try to login to phpmyadmin, I am getting an error on that page.
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve
I'm not sure what is wrong with my code. I hope you can help. Here is my Dockerfile:
FROM php:7.1.5-apache
RUN apt-get update && apt-get install -y \
libicu-dev \
libpq-dev \
libmcrypt-dev \
mysql-client \
git \
zip \
unzip \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install \
intl \
mbstring \
mcrypt \
pcntl \
pdo_mysql \
pdo_pgsql \
pgsql \
zip \
opcache
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
ENV APP_HOME /var/www/html
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
RUN sed -i -e "s/html/html\/webroot/g" /etc/apache2/sites-enabled/000-default.conf
RUN a2enmod rewrite
COPY . $APP_HOME
RUN composer install --no-interaction
RUN chown -R www-data:www-data $APP_HOME
CMD ["apache2", "-DFOREGROUND"]
and here is my docker-compose.yml file:
version: '2'
services:
cakeblog:
build: .
ports:
- "4000:80"
depends_on:
- mysql
links:
- mysql
volumes:
- ".:/var/www/html/"
environment:
- SECURITY_SALT=ashg4543323dd3434343434dsddet556kk
- MYSQL_URL=mysql
- MYSQL_USERNAME=root
- MYSQL_PASSWORD=test
mysql:
image: mysql:5.7
container_name: phpmyadmin_mysql
volumes:
- mysql_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=cakeblog
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- mysql:db
depends_on:
- mysql
ports:
- "8080:80"
environment:
- PMA_ARBITRARY=1
- TESTSUITE_PASSWORD=test
volumes:
mysql_data:
The Reason for this issue can be the wrong place for MySQL image specification in docker-compose.yml file.
Try With This One.
version: '2'
services:
mysql:
image: mysql:5.7
container_name: phpmyadmin_mysql
volumes:
- mysql_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=cakeblog
cakeblog:
build: .
ports:
- "4000:80"
depends_on:
- mysql
links:
- mysql
volumes:
- ".:/var/www/html/"
environment:
- SECURITY_SALT=ashg4543323dd3434343434dsddet556kk
- MYSQL_URL=mysql
- MYSQL_USERNAME=root
- MYSQL_PASSWORD=test
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- mysql:db
depends_on:
- mysql
ports:
- "8080:80"
environment:
- PMA_ARBITRARY=1
- TESTSUITE_PASSWORD=test
volumes:
mysql_data: