In my new Symfony application, I am trying to run docker-compose build when I get an error:
In my root bin folder I have the file from the error message. I am starting to question if this is a path problem? Can someone please help? Maybe it is something wrong with volume definition in the docker file I posted below.
RUN /var/www/html/bin/app_build.sh:
#19 0.164 /bin/sh: 1: /var/www/html/bin/app_build.sh: not found
version: "3.9"
services:
app-www:
container_name: app-www
hostname: app-www
restart: unless-stopped
entrypoint: apache2-foreground
build:
context: .
args:
ENVIRONMENT: local
volumes:
- ./www:/var/www/html
- ./.docker/.ssh:/root/.ssh
- ./www/node_modules:/var/www/html/node_modules:rw,cached
- ./www/vendor:/var/www/html/vendor:rw,cached
ports:
- "8080:80"
- "8081:443"
depends_on:
- redis
redis:
image: redis:6.2-alpine
restart: always
ports:
- '6363:6379'
command: redis-server --save 20 1 --loglevel warning
volumes:
- cache:/data
volumes:
cache:
driver: local
and dockerfile
FROM php:7.4-apache
ENV TZ="Europe/Zurich"
ARG COMPOSER_TOKEN
ENV COMPOSER_TOKEN=${COMPOSER_TOKEN}
# Debian Packages
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get --yes --no-install-recommends install libxml2-dev libgmp-dev zip npm zlib1g-dev libpng-dev libonig-dev git unzip tzdata \
&& npm install --global yarn
# PHP Extensions
RUN docker-php-ext-install soap bcmath gmp pdo pdo_mysql intl opcache gd json mbstring gmp \
&& docker-php-ext-enable soap bcmath gmp pdo pdo_mysql intl opcache gd json mbstring gmp \
&& pecl install xdebug \
&& pecl install redis \
&& docker-php-ext-enable xdebug redis
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN mkdir /root/.composer && echo "${COMPOSER_TOKEN}" > /root/.composer/auth.json
# Configure PHP
COPY ./config/docker/php/php.ini /usr/local/etc/php/php.ini
# Configure Apache
RUN a2enmod headers
RUN a2enmod rewrite
RUN a2enmod ssl
RUN rm -rf /etc/apache2/sites-enabled/* /etc/apache2/sites-available/
COPY ./config/docker/apache2/breitling.conf /etc/apache2/sites-enabled
COPY ./config/docker/apache2/ssl/ /etc/apache2/ssl/
# Deploy & Build app
COPY . /var/www/html/
RUN /var/www/html/bin/app_build.sh
# Fix permissions
RUN chmod -R 777 /var/www/html/var/
EXPOSE 80 443
ENTRYPOINT /var/www/html/bin/entrypoint.sh
I am not sure what is wrong as this is the main config for my project. And I am running it on MacOs.
After looking into these lines:
COPY . /var/www/html/
RUN /var/www/html/bin/app_build.sh
I would expect that inside path /var/www/html/ there is again www directory.
My guess is that you need only the contents of the www dir copied into the docker image. Then your copy command should look like this:
COPY ./www/ /var/www/html/
Give it a shot :-)
Related
I'm new to Docker. Trying to deploy dockerized laravel app using elastic beanstalk. Current Docker files -
docker-compose.yml -
version: '3'
services:
#PHP Service
app:
build:
context: ./
dockerfile: Dockerfile
image: admin
container_name: admin-app
restart: unless-stopped
working_dir: /usr/share/nginx/app/
volumes:
- ./:/usr/share/nginx/app/
networks:
- app-network
nginx:
image: nginx:stable-alpine
container_name: admin-nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./:/usr/share/nginx/app/
- ./nginx/conf.d/:/etc/nginx/conf.d
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
and Dockerfile
FROM php:7.4-fpm
ARG uid=1000
ARG user=sammy
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libcurl4-openssl-dev pkg-config libssl-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
RUN pecl install mongodb && docker-php-ext-enable mongodb && \
pecl install xdebug && docker-php-ext-enable xdebug
RUN pecl config-set php_ini /etc/php.ini
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Add user for laravel application
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Copy existing application directory contents
COPY . /usr/share/nginx/app
WORKDIR /usr/share/nginx/app
RUN chown -R $user:$user .
USER $user
RUN chown -R $user:$user storage bootstrap/cache
RUN chmod -R 775 storage bootstrap/cache
RUN composer install
RUN php artisan cache:clear
RUN php artisan view:clear
RUN php artisan config:clear
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
It works fine at local machine when I run docker compose up -d only if I have already run composer install otherwise throws following error
It is ok for development purpose I have to run composer install once, but for production, I think it is not right way to manually do composer install every time new version is deployed. Doesn't the command RUN composer install at Dockerfile install the required dependencies? I can see progress bar of dependencies being installed but no vendor folder is generated if I ssh into container. Again it works fine if I ssh into instance and manually install dependencies.
I have deployed a nodejs app also successfully using elastic beanstalk. There the dependencies were installed properly using command RUN npm install at Dockerfile. I don't see any difference in the process. Do I have to include vendor folder also in the zip file?. Please suggest correct way to deploy.
I am trying to update php version on the Docker
This is how my Dockerfile looks like
FROM php:7.2-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -d /home/ubuntu ubuntu
RUN mkdir -p /home/ubuntu/.composer && \
chown -R ubuntu:ubuntu /home/ubuntu
# Set working directory
WORKDIR /var/www
USER ubuntu
I have changed the php version to 7.3, and I tried to delete all docker containers and recreate it docker rm -vf $(docker ps -a -q). And then I built my docker containers using docker-compose build --nocache --pull.
docker-compose.yaml file looks like this:
version: "3.7"
services:
app:
build:
context: ./
dockerfile: ./docker/Dockerfile
image: myapp
container_name: myapp-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- myapp
But still the php version is stated as 7.2.
Any advice?
To remove all containers/images/networks/.. run:
docker system prune -a
Then try to build the image.
If that don't works: can you give the logs, where the wrong version will pulled?
On a remote VPS, I am mounting volumes thanks to this docker-compose :
version: '3.3'
services:
webapp:
build:
context: ./docker/webapp/
volumes:
- '${RELEASES_DIRECTORY}:/var/apps/site.org/releases'
- '${REPO_DIRECTORY}:/var/apps/site.org/repo'
- '${SHARED_DIRECTORY}:/var/apps/site.org/shared'
- './docker/webapp/over.php.ini:/usr/local/etc/php/conf.d/over.php.ini'
environment:
- APP_ENV=prod
- APP_DEBUG=0
- APP_DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}#${MYSQL_HOST}/${MYSQL_DATABASE}
- MYSQL_SERVER_VERSION=${MYSQL_SERVER_VERSION}
- MAILER_DSN=sendgrid+api://${SENDGRID_API_KEY}#default
working_dir: /var/apps/site.org
command: php-fpm
Here is the relative Dockerfile:
FROM php:7.4-fpm-alpine
# OS DEPENDENCIES
RUN apk update
RUN apk add --no-cache bash git curl libmcrypt libmcrypt-dev openssh-client icu-dev
RUN apk add --no-cache libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev zip libzip-dev g++ make autoconf
RUN apk add --no-cache php7-mysqli
RUN docker-php-source extract
RUN docker-php-source delete
RUN docker-php-ext-install soap intl zip
RUN docker-php-ext-install opcache
RUN docker-php-ext-install mysqli pdo pdo_mysql
#Creation APP Directory
RUN mkdir -p /var/apps
RUN mkdir -p /var/apps/site
# COMPOSER INSTALLATION
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# EXORT COMPOSER GLOBAL PATH
RUN echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
RUN source ~/.bashrc
# INSTALL NODE & NPM
RUN apk add --update nodejs npm
RUN npm config set production
RUN export NODE_ENV=production
On my local machine, when I go inside the docker throung docker exec, every mapped directories are root:root but on my remote host (VPS), they are 1001:1001 and I donèt get where does it can come from ?
I tried to re-install docker and docker-compose but I have the same behaviour.
The VPS runs
Unbuntu 18.04
Docker version 19.03.8, build afacb8b7f0
docker-compose version 1.25.5, build 8a1c60f6
When you bind host files to a docker container (bind mounting), the file's permissions aren’t changed.
Your VPS probably has those files owned by a user whose uid is 1001, while the same files on your system are owned by root.
I have this docker-compose file
version: "3.7"
services:
develop:
build:
args:
user: sineverba
uid: 1000
context: ./
container_name: tpaw-develop
image: tpaw-develop:0.1.0
volumes:
- ./:/home/sineverba/app
networks:
- develop-tpaw
networks:
develop-tpaw:
driver: bridge
I can launch it with docker-compose run --rm develop.
I want pass that args as variable from docker-compose command and not hard-coding it.
Is it possible?
I did try with
version: "3.7"
services:
develop:
build:
args:
user: ${CURRENT_USER}
uid: 1000
context: ./
And launch
CURRENT_USER=$(whoami) docker-compose build app
But Docker created a container with user $user inside
PS this is the main Dockerfile
FROM php:7.4-cli
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Setup PHPXDebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
#WORKDIR /var/www
WORKDIR /home/$user/app
USER $user
ENTRYPOINT /bin/bash
I have a setup using a Docker container with Apache2, PHP7, and Xdebug installed. The host system runs Ubuntu 16.04. I have installed Eclipse Neon latest download on the host computer and have tried many different configurations to get Xdebug working. I have configured the container to expose ports 80 and 9000 and have configured Xdebug for remote start and port 9000 usage. When I try to configure eclipse debugging it tells me that port 9000 is in use and will not connect. I've searched the web for any info that would help, but came up with nothing.
Here is the web server configuration code for the docker container:
FROM php:7.0.19-apache
COPY config/php.ini /usr/local/etc/php/
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
git \
&& docker-php-ext-install -j$(nproc) iconv 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\
&& pecl install xdebug-2.5.0 \
&& docker-php-ext-enable xdebug
# Installation of Composer
RUN cd /usr/src && curl -sS http://getcomposer.org/installer | php
RUN cd /usr/src && mv composer.phar /usr/bin/composer
# Installation of tools with composer
RUN composer global require --no-plugins --no-scripts phpdocumentor/phpdocumentor
RUN composer global require --no-plugins --no-scripts squizlabs/php_codesniffer
RUN composer global require --no-plugins --no-scripts phpunit/phpunit
RUN composer global require --no-plugins --no-scripts phpunit/dbunit
RUN composer global require --no-plugins --no-scripts phploc/phploc
RUN composer global require --no-plugins --no-scripts phpmd/phpmd
RUN composer global require --no-plugins --no-scripts simpletest/simpletest
ENV PATH /root/.composer/vendor/bin:$PATH
Here are the php.ini settings` for Xdebug:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
xdebug.profiler_enable_trigger = 1
xdebug.trace_enable_trigger = 1
xdebug.remote_enable=1
xdebug.remote_host=172.18.0.1
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
And here is the docker-compose code that exposes the ports and links in a database container:
version: '2'
services:
webserver:
build: ./docker/webserver
ports:
- "80:80"
- "443:443"
- "9000:9000"
volumes:
- /home/www:/var/www
links:
- db
db:
image: mysql:5.5
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=mypassword
myadmin:
image: phpmyadmin/phpmyadmin:4.6
ports:
- "8080:80"
links:
- db
environment:
MYSQL_ROOT_PASSWORD: mypassword
I'd appreciate any help in getting the debugger working so that I can use it for setting breakpoints. I have installed theeasiestxdebug extension for Firefox and intend to use that as the control for debugging when I get everything working.
Thanks in advance.