Docker "Invalid mount path app/symfony" must be absolute - symfony

Im trying to setup Webpack to run with docker. I'm looking to put it in its own container, build the files and then nginx will serve that produced code on its container.
My docker-compose.yml file looks like:
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
build: ./php/
expose:
- 9000
links:
- mysql
volumes_from:
- app
app:
image: php:7.0-fpm
volumes:
- ./app/symfony:/var/www/html
command: "true"
web:
build: ./webpack
volumes_from:
- app
mysql:
image: mysql:latest
volumes_from:
- data
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
data:
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
My code is stored in the app/symfony directory. The Dockerfile for the webpack container is currently:
FROM node:wheezy
WORKDIR /app
RUN apt-get update
RUN apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - && apt-get install nodejs -y
RUN npm install webpack -g
RUN npm install
CMD webpack --watch --watch-polling
I am getting the error:
ERROR: for web Cannot create container for service web: invalid bind mount spec "a60f89607640b36a468b471378a6b7079dfa5890db994a1228e7809b93b8b709:app/symfony:rw": invalid volume specification: 'a60f89607640b36a468b471378a6b7079dfa5890db994a1228e7809b93b8b709:app/symfony:rw': invalid mount config for type "volume": invalid mount path: 'app/symfony' mount path must be absolute
ERROR: Encountered errors while bringing up the project.
I want webpack to take the code in app/symfony, and build any assets, and then the nginx container will serve those.

I had a similar issue.
my docker-compose.yml looked like this
version: '3.1'
services:
nginx:
build:
context: ./server
ports:
- "8080:80"
volumes:
- ./fw:opt/www/app/
and got the error "invalid mount path: 'opt/www/app' mount path must be absolute
"
I resolved it by changing the mount path like this by adding a slash in front of the path.
volumes:
- ./fw: /opt/www/app/

SOLUTION:
If you have this docker-compose.yaml in your root of project. Then make sure you have a '/' before app.
As per Docker Documentation:
docker run -dp 3000:3000 \
-w /app -v "$(pwd):/app" \
node:12-alpine \
sh -c "yarn install && yarn run dev"
This works perfectly.

Related

how to add lua-cjson to my nginx lua container?

I am using this docker-compose to create a Lua supported Nginx:
version: '3.9'
services:
nginx:
container_name: local_nginx
image: fabiocicerchia/nginx-lua
environment:
- REDIS_SERVER=172.26.0.1
ports:
- 8089:80
- 8053:8053
volumes:
- /home/navid/lua_project/nginx/nginx.conf:/etc/nginx/nginx.conf
- /home/navid/lua_project/nginx/www:/usr/share/nginx/html
- /home/navid/lua_project/lib/resty/redis.lua:/usr/local/share/luajit-2.0.4/resty/redis.lua
- /home/navid/lua_project/lib/resty/kafka:/usr/local/share/lua/5.1/resty/kafka
extra_hosts:
- host.docker.internal:host-gateway
and now I need to add cjson library to my container. I try the build method on my host machine but it throws this exception:
lua.h: No such file or directory
And also I added these line to make it on my container:
- /home/navid/lua_project/lib/resty/lua-cjson:/usr/local/share/lua/5.1/resty/cjson
command:
- |
cd /usr/local/share/lua/5.1/resty/cjson
autoreconf -i -v --force
./configure
make
make install
but it failed on run phase with this error:
exec: line 38: cd /usr/local/share/lua/5.1/resty/cjson autoreconf -i
-v --force ./configure make make install : not found
is there any straightway to install cjson on my container?
Update:
I finally built and upload cjson.so into my docker container but I am getting this error:
loading module 'cjson' from file '/usr/local/lib/lua/5.1/cjson.so':
Error relocating /usr/local/lib/lua/5.1/cjson.so: __snprintf_chk: symbol not found
So is there any other alternative library that has good performance?
This could be the solution to your problem.
This is a dockerfile that allows having cjson working:
FROM fabiocicerchia/nginx-lua:1-alpine-compat
RUN apk add gcc musl-dev coreutils \
&& luarocks install lua-cjson
More details on it: https://github.com/fabiocicerchia/nginx-lua/issues/34
It seems you're trying to use an openresty module with a standard nginx installation, which doesn't work because they aren't the same thing. Openresty is nginx + LuaJIT.

Docker for WordPress slow

Problem:
I have a problem with WordPress & Docker because the slow loading time (+- 7 seconds) of my website. I am not sure why this happends but I think it has something to do with the external database or the shared volumes.
Setup:
I have a custom Dockerfile built on WordPress with XDebug and Mailhog. This Dockerfile is included within my docker-compose.yml, the other services my docker-compose contains are WP-CLI and Mailhog. My Database is hosted on an Amazon RDS so I can share it with my colleagues.
Code:
My Dockerfile looks like this:
FROM wordpress:latest
# Plugins & Media
RUN mkdir -p /var/www/html/wp-content/plugins
RUN mkdir -p /var/www/html/wp-content/uploads
RUN chown -R www-data:www-data /var/www
RUN find /var/www/ -type d -exec chmod 0755 {} \;
RUN find /var/www/ -type f -exec chmod 644 {} \;
# Mailhog
RUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && \
chmod +x /usr/local/bin/mhsendmail
RUN echo 'sendmail_path="/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 --from=noreply#examle.com"' > /usr/local/etc/php/conf.d/mailhog.ini
# Xdebug
ENV XDEBUG_PORT 9000
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=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.profiler_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.profiler_output_name=cachegrind.out.%t" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.profiler_output_dir=/tmp" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "max_input_vars=2000" >> /usr/local/etc/php/conf.d/custom.ini \
&& rm -rf /usr/local/etc/php/conf.d/opcache-recommended.ini
EXPOSE 9000
My Docker-compose.yml looks like this:
version: "3.7"
services:
wordpress:
container_name: "${PROJECT_NAME}_wordpress"
restart: always
build:
context: ./
dockerfile: ./Dockerfile
ports:
- "8888:80"
- "443:443"
environment:
WORDPRESS_DB_NAME: "${PROJECT_NAME}"
WORDPRESS_DB_HOST: "${MYSQL_HOST}"
WORDPRESS_DB_USER: "${MYSQL_USER}"
WORDPRESS_DB_PASSWORD: "${MYSQL_PASSWORD}"
WORDPRESS_DEBUG: 1
XDEBUG_CONFIG: remote_host=host.docker.internal
WORDPRESS_CONFIG_EXTRA: |
define('FS_METHOD', 'direct');
volumes:
- "wordpress:/var/www/html"
- "./build/uploads:/var/www/html/wp-content/uploads:cached"
- "./build/plugins:/var/www/html/wp-content/plugins:cached"
- "./build/themes:/var/www/html/wp-content/themes:cached"
cli:
container_name: "${PROJECT_NAME}_cli"
image: "wordpress:cli"
volumes:
- "wordpress:/var/www/html"
- "./build/plugins:/var/www/html/wp-content/plugins:cached"
depends_on:
- wordpress
mailhog:
container_name: "${PROJECT_NAME}_mailhog"
image: mailhog/mailhog
depends_on:
- wordpress
ports:
- "1025:1025"
- "8025:8025"
volumes:
wordpress: null
But I can't find out why it is so slow; I got version 2.1.09.3 of Docker Desktop and working on a fast Mac or Windows.
Can someone help me or point me in the right direction?
Edits
If I look in the docker stats my CPU is around 0.01% and my MEM is around 2.73% so that can't be the problem.
Found out the biggest problem is connecting to the external database. If I move over to a local database the loading time is a lot faster (+- 1 sec).
There some issues for Mac & Windows Volume performance.
Link for more details:
Docker Wordpress super slow
In Mac and Windows there are some volumes performance issues that we should consider.
I made change in my docker-compose.yml
Note as I changed the short syntax to long syntax.
This notation permits add consistency option.
I added wp-content and php-conf (to get php.ini) because they are files directory most frequently called every time when a Wordpress page is loaded in browser.
services:
wordpress:
...
volumes:
- ./data:/data
- ./scripts:/docker-entrypoint-initwp.d
#- ./wp-content:/app/wp-content
- type: bind
source: ./wp-content
target: /app/wp-content
consistency: cached
#- ./php-conf:/usr/local/etc/php
- type: bind
source: ./php-conf
target: /usr/local/etc/php
consistency: cached

Gitlab CI : ./bin/phpunit: No such file or directory

I try to understand how to use Gitlab CI in a laravel project with PHPUnit. As written in the documentation of Laravel, I have added the PHPUnit-bridge with composer require --dev symfony/phpunit-bridge
.
MY gilab-ci.yml file
image: php:7.2-cli
services:
- mysql:latest
cache:
paths:
- vendor/
stages:
- connect
- test
- deploy
variables:
# Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: deshautsdebats
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_PASSWORD: root
before_script:
- apt-get update -yqq
- apt-get install git -yqq zlib1g-dev
# Install mysql driver
- docker-php-ext-install pdo_mysql zip
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
test:
stage: test
script:
- ls -lad bin/
- ./bin/phpunit
When I enter ./bin/phpunit in local it works but when it's made by the CI if says :
/bin/bash: line 90: ./bin/phpunit: No such file or directory
I tried to replace ./bin/phpunitby ./vendor/bin/phpunit but it throws the same error... Do you have any idea?
Thanks,
I figure this out by following those steps

Docker Compose Link Containers for Phpunit with Wordpress, MySQL

I would like to use a docker-compose app to run unit tests on a wordpress plugin.
Following (mostly) this tutorial I have created four containers:
my-wpdb:
image: mariadb
ports:
- "8081:3306"
environment:
MYSQL_ROOT_PASSWORD: dockerpass
my-wp:
image: wordpress
volumes:
- ./:/var/www/html
ports:
- "8080:80"
links:
- my-wpdb:mysql
environment:
WORDPRESS_DB_PASSWORD: dockerpass
my-wpcli:
image: tatemz/wp-cli
volumes_from:
- my-wp
links:
- my-wpdb:mysql
entrypoint: wp
command: "--info"
my-phpunit:
image: phpunit/phpunit
volumes_from:
- my-wp
links:
- my-wpdb
This tutorial got me as far as creating the phpunit files (xml, tests, bin, .travis), with the exception that I had to install subversion manually:
docker exec wp_my-wp_1 apt-get update
docker exec wp_my-wp_1 apt-get install -y wget git curl zip vim
docker exec wp_my-wp_1 apt-get install -y apache2 subversion libapache2-svn libsvn-perl
And run the last part of bin/install-wp-tests.sh manually in the database container:
docker exec wp_my-wpdb_1 mysqladmin create wordpress_test --user=root --password=dockerpass --host=localhost --protocol=tcp
I can run phpunit: docker-compose run --rm my-wp phpunit --help.
I can specify the config xml file:
docker-compose run --rm my-wp phpunit --configuration /var/www/html/wp-content/plugins/my-plugin/phpunit.xml.dist
However, the test wordpress installation is installed in the my-wp container's /tmp directory: /tmp/wordpress-tests-lib/includes/functions.php
I think I have to link the my-phpunit containers /tmp to the one in my-wp?
This doesn't answer my question, but as a solution to the problem, there is a github repo for a Docker Image that provides the wanted features: https://github.com/chriszarate/docker-wordpress as well as a wrapper you can invoke it through: https://github.com/chriszarate/docker-wordpress-vip
I wonder if for the initial set-up (noted in the question), it might make more sense to add Phpunit to the Wordpress container, rather than making a separate container for it.

Dockerize wordpress

Trying to dockerise wordpress I figure out this scenenario:
2 data volume containers, one for the database (bbdd) and another for wordpress files (wordpress):
sudo docker create -v /var/lib/mysql --name bbdd ubuntu:trusty /bin/true
sudo docker create -v /var/www/html --name wordpress ubuntu:trusty /bin/true
Then I need a container for mysql so I use the official mysql image from docker hub and also the volume /var/lib/mysql from the first data container:
docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql:5.6
Then I need a container for apache/php so I use official wordpress image from docker hub and also the volume /var/lib/mysql from the first data container:
docker run --volumes-from wordpress --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache
What I understand from docker docs is that if I don't remove the data containers, I'll have persistance.
However if I stop and delete running containers (apache and mysql) and recreate them again with last commands, data get lost:
docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql:5.6
docker run --volumes-from wordpress --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache
However if I create the containers without data containers, it seems to work as I expected:
docker run -v /home/juanda/project/mysql:/var/lib/mysql --name mysql -e MYSQL_ROOT_PASSWORD="juanda" -d mysql:5.6
docker run -v /home/juanda/project/wordpress:/var/www/html --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache
You need to run the data container for once to make it persistent:
sudo docker run -v /var/lib/mysql --name bbdd ubuntu:trusty /bin/true
sudo docker run -v /var/www/html --name wordpress ubuntu:trusty /bin/true
This is an old bug of Docker described here. You may be affected if your Docker version is old.
In a very simplified test case this appears to work as advertised and documented in Creating and mounting a Data Volume Container:
prologic#daisy
Thu Apr 30 08:18:45
~
$ docker create -v /test --name data busybox /vin/true
Unable to find image 'busybox:latest' locally
latest: Pulling from busybox
cf2616975b4a: Pull complete
6ce2e90b0bc7: Pull complete
8c2e06607696: Already exists
busybox:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:38a203e1986cf79639cfb9b2e1d6e773de84002feea2d4eb006b52004ee8502d
Status: Downloaded newer image for busybox:latest
6f5fc1d2e33654867cff8ffdb60c5765ced4b7128441ae2c6be24b68fb6454ef
prologic#daisy
Thu Apr 30 08:20:53
~
$ docker run -i -t --rm --volumes-from data crux /bin/bash
bash-4.3# cd /test
bash-4.3# ls
bash-4.3# touch foo
bash-4.3# echo "Hello World" >> foo
bash-4.3# cat foo
Hello World
bash-4.3# exit
prologic#daisy
Thu Apr 30 08:21:20
~
$ docker run -i -t --rm --volumes-from data crux /bin/bash
bash-4.3# cd /test
bash-4.3# ls
foo
bash-4.3# cat foo
Hello World
bash-4.3# exit
Note that I deleted the attached container to make sure the persistent data volume container's data was left in tact.
The data volume container and it's data would only disappear if you ran the following:
docker rm -v data
Note: the -v option to actually remove volumes.
See (specifically the -v/--volumes option):
$ docker rm -h
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
-f, --force=false Force the removal of a running container
(uses SIGKILL) --help=false Print usage -l, --link=false
Remove the specified link -v, --volumes=false Remove the volumes
associated with the container
For reference I am running:
prologic#daisy
Thu Apr 30 08:24:51
~
$ docker version
Client version: 1.6.0
Client API version: 1.18
Go version (client): go1.3.3
Git commit (client): 47496519da
OS/Arch (client): linux/amd64
Server version: 1.6.0
Server API version: 1.18
Go version (server): go1.3.3
Git commit (server): 47496519da
OS/Arch (server): linux/amd64
Update: For a quick example (which you can use in production) of a Dockerized Wordpress setup with full hosting support see: https://gist.github.com/prologic/b5525a50bb4d867d84a2
You can simply use docker-compose file as:
version: '3.3'
services:
# https://hub.docker.com/_/nginx
# Doesn't play well with wordpress fpm based images
# nginx:
# image: nginx:latest
# container_name: "${PROJECT_NAME}_nginx"
# ports:
# - "${NGINX_HTTP_PORT}:80"
# working_dir: /var/www/html
# volumes:
# - ./docker/etc/nginx:/etc/nginx/conf.d
# - ./logs/nginx:/var/log/nginx
# - ./app:/var/www/html
# environment:
# - NGINX_HOST=${NGINX_HOST}
# #command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/wordpress.conf > /etc/nginx/conf.d/wordpress.conf && nginx -g 'daemon off;'"
# links:
# - wordpress
# restart: always
# https://hub.docker.com/r/jwilder/nginx-proxy
nginx-proxy:
image: jwilder/nginx-proxy
container_name: "${PROJECT_NAME}_nginx-proxy"
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
# https://hub.docker.com/_/mysql
mysql:
image: mysql:${MYSQL_TAG}
# For MySQL 8.0
#image: mysql:8
#command: '--default-authentication-plugin=mysql_native_password'
container_name: "${PROJECT_NAME}_mysql"
ports:
- "${MYSQL_PORT}:3306"
volumes:
- ./data/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
restart: always
# https://hub.docker.com/_/wordpress
wordpress:
# -fpm or apache, unfortunately fpm doesn't work properly with nginx-proxy
image: wordpress:${WP_VERSION}-php${PHP_VERSION}-apache
container_name: "${PROJECT_NAME}_wordpress"
environment:
- VIRTUAL_HOST=${WP_HTTP_HOST}
- WORDPRESS_DB_HOST=mysql:3306
- WORDPRESS_DB_NAME=${MYSQL_DATABASE}
- WORDPRESS_DB_USER=${MYSQL_USER}
- WORDPRESS_DB_PASSWORD=${MYSQL_ROOT_PASSWORD}
working_dir: /var/www/html
volumes:
- ./app:/var/www/html
#- ./app/wp-content:/var/www/html/wp-content
- ./docker/etc/php-fpm/custom.ini:/usr/local/etc/php/conf.d/999-custom.ini
#depends_on:
# - mysql
ports:
- "${WP_HTTP_PORT}:80"
expose:
- ${WP_HTTP_PORT}
links:
- mysql
restart: always
# https://hub.docker.com/r/phpmyadmin/phpmyadmin
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: "${PROJECT_NAME}_phpmyadmin"
ports:
- "${PMA_PORT}:80"
expose:
- ${PMA_PORT}
environment:
VIRTUAL_HOST: ${PMA_HTTP_HOST}
PMA_HOST: mysql
depends_on:
- mysql
# #todo services
# jwilder/nginx-proxy
# https / letsencrypt
# composer
# mailhog
# redis
# phpredisadmin
# blackfire
networks:
default:
external:
name: nginx-proxy
SOURCE: https://github.com/MagePsycho/wordpress-dockerized

Resources