Docker-compose up missing files - laravel

My question is simple , when docker-compose build : some new folders will be generated using npm run prod command , I've added in my Dockerfile "ls -lhtr the_missingFolder" and I can see it's there.
After complete building I ran docker-compose up >> Boomm the folder not in the container , why ?
How can I fix that please.
FROM ubuntu:16.04
RUN apt-get update && apt install -y build-essential
RUN apt-get update -y && apt-get install -y openssl zip unzip git libpng-dev zlib1g-dev libicu-dev libtool g++
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt install -y composer
RUN apt-get install -y curl wget
RUN apt-get install -y autoconf automake pkg-config libgtk-3-dev nasm
RUN apt-get clean && apt-get update && apt-get install -y locales
RUN locale-gen en_US en_US.UTF-8
RUN apt-get install -y python-software-properties
RUN apt-get install -y software-properties-common
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt install -y php7.1-fpm php7.1-mbstring php7.1-xmlrpc php7.1-soap
php7.1-gd php7.1-xml php7.1-cli php7.1-zip php7.1-pgsql php7.1-curl
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . ./
COPY package*.json ./
RUN cp .env.docker .env
RUN npm install
RUN npm run prod
COPY . /usr/src/app/
WORKDIR /usr/src/app
RUN composer update
RUN composer install --no-interaction --prefer-dist --optimize-autoloader
RUN php artisan config:clear
RUN php artisan optimize
CMD bash -c "php artisan db:seed --class=App\\module\\role\\database\\seed\\role"
CMD bash -c "php artisan db:seed --class=App\\module\\notification\\database\\seed\\notification"
CMD bash -c "php artisan notifications:generate-files"
CMD bash -c "php artisan migrate"
CMD bash -c "composer install && php artisan serve --host=0.0.0.0 --port=8000"
EXPOSE 8000
Best regards

I had this problem before. In my case, I had a named volume that gets reused every time docker-compose up is ran.
I just destroyed the volume along with the containers using -v option in docker-compose down and everything is there the next time I ran docker-compose up.

Related

E: Package 'mysql-client' has no installation candidate in php-fpm image build using docker compose

Im fairly new to docker and so im trying to learn more about it using a laravel project, im following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
Ive adjusted the Dockerfile a bit from what the tutorial has but even the tutorial file causes the same result.
FROM php:7.3-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Install dependencies
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && apt-get install -y mysql-client \
RUN npm install -g npm
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo pdo_mysql
# 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
# Set working directory
WORKDIR /var/www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
But i keep getting the following error when i run docker-compose up -d:
E: Package 'mysql-client' has no installation candidate
ERROR: Service 'app' failed to build: The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y mysql-client nodejs build-essential vim git curl' returned a non-zero code: 100
Am i missing something?
I expected this to work since i am running apt-get update before installing mysql-client.
Thanks.
php:7.3-fpm now use Debian 10 (Buster) as its base image and Buster ships with MariaDB, so just replace mysql-client with mariadb-client should fix it.
If you still want to use the mysql client, it's called default-mysql-client now.
php:7.2-apache triggers the error as well, but I resolve it using php:7.2.18-apache
it worked for me: sudo apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
or alternatively apt-cache search mysql-server
find out your servers then sudo apt-get install default-mysql-server default-mysql-server-core mariadb-server-10.6 mariadb-server-core-10.6
in my case it was the above codes

Laravel, Nginx and Docker Container, Permission Denied

I have created a laravel project and put it in a docker container and it all seems to load fine, however at some point I get an error message saying:
There is no existing directory at "/Users/john/Documents/work/dashboard/src/storage/logs" and its not buildable: Permission denied
It is strange that Laravel is trying to write into a file or directory that is part of my local environment, instead of the docker container environment which I would expect to be something like:
/var/www/storage/logs
This is my docker-compose.yml:
version: '2'
services:
# The Web Server
web:
build:
context: ./
dockerfile: web.signup.dockerfile
working_dir: /var/www
volumes:
- ./src:/var/www
- /var/www/storage
env_file: 'src/.env'
ports:
- 80:80
volumes:
dbdata:
And this is my Dockerfile
FROM centos:latest
RUN set -ex \
&& yum install -y epel-release \
&& yum update -y mysql-client libmagickwand-dev \
&& yum install -y libmcrypt-devel \
&& yum install -y python-pip \
&& pip install --upgrade pip \
&& yum install -y zip unzip \
&& yum install -y java-1.8.0-openjdk \
&& yum clean all
RUN pip install --upgrade --ignore-installed six awscli
RUN yum install -y supervisor
RUN yum install -y php-pear php-devel
RUN pecl install imagick
# Add the Ngix
ADD nginx.repo /etc/yum.repos.d/nginx.repo
# Add the Centos PHP dependent repository
RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum update -y
# Installing Nginx
RUN yum -y install nginx
# Installing PHP
RUN yum -y --enablerepo=remi,remi-php72 install php-fpm php-common php-mcrypt php-mbstring
WORKDIR /var/www
ADD vhost.prod.conf /etc/nginx/conf.d/default.conf
COPY src/. /var/www
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& php composer.phar install --no-dev --no-scripts \
&& rm composer.phar
RUN chown -R apache:apache \
/var/www/storage \
/var/www/bootstrap/cache
EXPOSE 80
EXPOSE 9000
RUN mkdir -p /run/php-fpm
COPY supervisord.conf /supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]
Any ideas at all?
Works as designed,
you are mounting "src" from your current directory into the container.
volumes:
- ./src:/var/www
If you want to access your code inside the container you could add the files while building.
To fix your "bug",
chmod -R 777 /Users/john/Documents/work/dashboard/src/storage/logs
Would be ok a for local development environment
From my end, results are when no matter what folder permission we changed in the physical folder.
Delete everything in bootstrap/cache/* solved the issue.
In my case, I got this error when I ran out of HDD space and I cleared it
Only this helped:
rm bootstrap/cache/config.php
php artisan cache:clear
composer dump-autoload

Answer '29' to apt-get install prompt for xorg

I'm using docker to put together a script and its get stuck when this package xorg asks the prompt for the country of origin for the keyboard, I'll attach the image.
I've tried piping in the command like this from other answers I've read
RUN echo "29" | apt-get install -y xorg
But it didn't seem to work. I'm not sure how I get this to auto answer 29. Any help is appreciated.
Reference to docker file
FROM ubuntu:16.04
MAINTAINER Joe Astrahan <email#hey.com>
VOLUME ["/var/www"]
#Install Apache & Basic Software
RUN apt-get update && \
apt-get install -y \
software-properties-common \
apache2 \
curl \
libcurl3 \
libcurl3-dev
#Install PHP 7.0 & mod apache
RUN apt-get install -y \
php7.0 \
php7.0-cli \
libapache2-mod-php7.0 \
php7.0-gd \
php7.0-json \
php7.0-ldap \
php7.0-mysqlnd \
php7.0-pgsql \
php7.0-curl \
php7.0-xml \
php7.0-xsl \
php7.0-zip \
php7.0-sqlite3 \
php7.0-ldap \
php7.0-json \
php7.0-mbstring \
php7.0-soap \
php7.0-intl \
php7.0-bcmath \
php7.0-gmp \
php7.0-mcrypt
#Install mysql, vim and openssl
RUN apt-get install -y \
mysql-client \
vim \
openssl
# Copy an initial PHP.ini file into the system with default settings
#COPY config/php.ini /etc/php5/apache2/php.ini
# Install php-5.5.30
#ADD config/install_php-5.5.30.sh /tmp/install_php-5.5.30.sh
#RUN /bin/bash /tmp/install_php-5.5.30.sh
# Set environment variables for Apache so we know its user and group names
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
# Configure Apache SSL and Standard Virtualhosts
COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/apache_default-ssl.conf /etc/apache2/sites-available/default-ssl.conf
COPY config/run /usr/local/bin/run
# Configure SSL Directories & Create Temporary SSL Keys
RUN mkdir /etc/apache2/ssl
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt -subj "/C=US/ST=Florida/L=Fort Lauderdale/O=Pool Service Software LLC/OU=IT Department/CN=dev.poolservice.software.local"
RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite
#Configure SSL On Apache2 & Headers Mod
RUN a2enmod ssl
RUN a2enmod headers
RUN service apache2 restart
RUN a2ensite default-ssl.conf
RUN service apache2 restart
#RUN apt-get install -y wkhtmltopdf
#Download and install composer and git
RUN apt-get install git -y
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
#Install Zip & Unzip
RUN apt-get install zip unzip -y
#Install NodeJS
#RUN curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
RUN apt-get install -y nodejs
RUN apt-get install -y npm
#Install UglifyCSS and JS
RUN npm install -g uglify-js
RUN npm install -g uglifycss
RUN npm install -g less
# Download and install wkhtmltopdf
RUN apt-get install -y build-essential
RUN echo "29" | apt-get install -y xorg
RUN apt-get install -y libssl-dev
RUN apt-get install -y libxrender-dev
RUN apt-get install -y wget
RUN apt-get install -y gdebi
RUN apt-get install -y libxrender1
RUN apt-get install -y xfonts-utils
RUN apt-get install -y xfonts-base
RUN apt-get install -y xfonts-75dpi
RUN apt-get install -y libfontenc1
RUN apt-get install -y x11-common
RUN apt-get install -y xfonts-encodings
RUN apt-get install -y libxfont1
RUN apt-get install -y fontconfig
RUN wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
RUN gdebi --n wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
RUN echo 'exec xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$#"' | tee /usr/local/bin/wkhtmltopdf.sh >/dev/null && sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh
EXPOSE 80
EXPOSE 443
CMD ["/usr/local/bin/run"]
There are quite a few issues I see with the Dockerfile provided.
Defining a volume inside the Dockerfile provides little to no value. It's much better to define this in your docker-compose.yml or as part of your run command. I've got a blog post going through the issues with this.
Splitting up the apt-get update from the later apt-get install commands can result in situations where the apt-get install will fail. There's a section in the best practices about this.
For your error message, I'd run apt-get in the noninteractive mode. You can also preconfigure debconf if you need a non-default value set during install.
Splitting each apt-get into a separate RUN command is creating lots of excessive layers, these should be merged where possible. This is also described in the best practices documentation.
Here's a sample of an install command that works for me taking the above into account:
FROM ubuntu:16.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
xorg \
libssl-dev \
libxrender-dev \
wget \
gdebi \
libxrender1 \
xfonts-utils \
xfonts-base \
xfonts-75dpi

launch basic bash script on docker build from windows system

I would like to construct a docker image based from script bash for provisioning my system.
I try to build my image and docker tell me "Successfully built" but when I try to launch this I can see this message : "No such file or directory" and I can't viewing container in Kitematic application.
If I launch docker inspect on my container (created correctly but not launched) I can view a ExitCode 127.
Can you help me to understand issue and also help me to launch correctly a simple script bash for provisionning image docker.
dockerfile :
FROM ubuntu:trusty
MAINTAINER barbie rambo <barbierambo#mymail.com>
RUN apt-get update \
&& apt-get install -y openjdk-7-jdk wget openssh-server tar vim
COPY scripts/base.sh /home/docker/scripts/base.sh
RUN chmod 744 /home/docker/scripts/base.sh
ENTRYPOINT /home/docker/scripts/base.sh
my base.sh script
#!/usr/bin/env bash
# Set non-interactive mode
#export DEBIAN_FRONTEND=noninteractive
# Update the box
apt-get -y update
apt-get -y install linux-headers-$(uname -r) build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
apt-get -y install curl unzip
apt-get -y install software-properties-common
apt-get -y install gnupg2
# others tools
sudo apt-get -y install nano
sudo apt-get -y install vim
sudo apt-get -y install aptitude
sudo apt-get -y install git
sudo apt-get -y install openjdk-8-jre
sudo apt-get -y install whois
sudo apt-get -y install dos2unix
check whether /home/docker/scripts/base.sh has EOL as UNIX/OSX Format, if not you can do EOL Conversion in Notepad++
open file in Notepad++ -> Edit -> EOL Conversion -> UNIX/OSX Format -> Save
then rebuild docker image
If you want to get into container ten run following:
docker ps -a
and use container id
docker exec -i -t [containerID] bash
and check whether file /home/docker/scripts/base.sh exists

ADD command not working Docker

FROM phusion/baseimage:0.9.16
MAINTAINER Raheel <raheelwp#gmail.com>
RUN apt-get update
RUN apt-get -y install apache2 libapache2-mod-php5 curl git
RUN add-apt-repository ppa:ondrej/php5-5.6
RUN apt-get update
RUN apt-get -y install python-software-properties
RUN apt-get update
RUN apt-get -y --force-yes install php5 php5-cli php5-mcrypt php5-curl php5-xdebug php5-json
RUN apt-get clean
RUN php5enmod mcrypt
RUN rm -rf /var/www/html
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
ADD /home/raheel/code/laravel-app /var/www/laravel-app
EXPOSE 80
COPY setup-laravel.sh /var/www/laravel-app/setup-laravel.sh
RUN ["chmod", "+x", "/var/www/laravel-app/setup-laravel.sh"]
ENTRYPOINT ["/var/www/laravel-app/setup-laravel.sh"]
I created the above Dockerfile to run laravel application.
Then i ran docker build -t raheelwp/laravel-app . command and it created the image without name. Then i ran docker tag imageid raheelwp/laravel-app . After this when i check docker images it shows my image with name.
So far so good. But when i run docker run -t raheelwp/laravel-app and then login into container by docker exec -it containerid bash and do the ls on /var/www directory there is no laravel-app folder present there.
I am new to docker and this is my first ever docker file. I would be very thankful to you to please guide me why i am having this problem and how to fix this.
Thanks

Resources