So I have a trouble with mount new format version 2 docker compose file.
I have the code in folder wordpress inside where is location docker-compose file also I have inside the folder code docker file like this:
FROM debian:jessie
VOLUME /var/www/wordpress
When I used old format like this:
application:
build: code
volumes:
- ./wordpress:/var/www/wordpress
- ./logs/wordpress:/var/www/wordpress/app/logs
tty: true
db:
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: somename
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
build: php-fpm
ports:
- 9001:9001
volumes_from:
- application
links:
- db
nginx:
build: nginx
ports:
- 8080:80
links:
- php
volumes_from:
- application
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- 81:80
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- application
- php
- nginx
When I started use version '2' the same as code as previous version I got any error so I reformat my compose file and move dockerfile from code folder to insider main folder where is location docker-compose file. My new version docker-compose became looks like as:
version: '2'
services:
web:
build: .
volumes:
- /wordpress:/var/www/wordpress
- /logs/wordpress:/var/www/wordpress/app/logs
tty: true
db:
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: somename
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
build: php-fpm
ports:
- 9001:9001
volumes_from:
- web
links:
- db
nginx:
build: nginx
ports:
- 82:82
links:
- php
volumes_from:
- web
volumes:
- /logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- 81:80
volumes:
- /elk/logstash:/etc/logstash
- /elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- web
- php
- nginx
Finally after reformat the code docker-compose was successfully build and up but when I open my php and nginx container inside both of them in /var/www/worpdress I have just empty folder app is not my wordpress project.
In which place I was mistake with settings mount project volume?
Thanks in advance.
The problem is with the way you are defining the local directories to be used for the volumes. In your previous version, you were using ./wordpress, while in the new one, you're using just /wordpress.
When referencing local directories for volume mappings, they always have to start with ./ - please try this:
version: '2'
services:
web:
build: .
volumes:
- ./wordpress:/var/www/wordpress
- ./logs/wordpress:/var/www/wordpress/app/logs
One more thing: I recommend to always enclose the volume mappings in double quotes to avoid issues with space characters, e.g.:
version: '2'
services:
web:
build: .
volumes:
- "./wordpress:/var/www/wordpress"
- "./logs/wordpress:/var/www/wordpress/app/logs"
Related
This is my docker-compose.yml
version: '3.9'
networks:
bedrock:
services:
web:
container_name: kawa-web
image: nginx:stable-alpine
volumes:
- ./:/var/www/html:delegated
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- 8080:80
depends_on:
- php
- mysql
networks:
- bedrock
php:
container_name: kawa-php
image: nanoninja/php-fpm:8.0
volumes:
- ./:/var/www/html
- ./docker/config/php.ini:/usr/local/etc/php/conf.d/php.ini
ports:
- 9000:9000
networks:
- bedrock
mysql:
container_name: kawa-db
image: mysql:8
volumes:
- ./docker/db:/var/lib/mysql:delegated
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
networks:
- bedrock
node:
container_name: kawa-node
build:
context: .
dockerfile: node.dockerfile
volumes:
- ./:/var/www/html
networks:
- bedrock
Content of node.dockerfile
FROM node:18-alpine
WORKDIR /var/www/html
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
When I run docker compose up -d it shows
failed to solve: error from sender: open /path/to/project/docker/db/#innodb_temp: permission denied
How can I fix this? Or any another way to run nodejs inside PHP container maybe?
When your Compose setup has:
services:
mysql:
volumes:
- ./docker/db:/var/lib/mysql:delegated
node:
build:
context: .
The MySQL data directory is in the ./docker/db directory. That's inside the . build-context directory of the Node application, so docker-compose build among other things sends the entire MySQL data to itself, and if the database is currently running, you could get lock or permission problems like this.
The best approach to work around this is to split your application into separate directories, and have each language component only build its own subdirectory.
$ ls -1F
data/
docker-compose.yml
js/
php/
static/
$ ls -1F js
Dockerfile
index.js
node_modules/
package.json
package-lock.json
# docker-compose.yml
version: '3.8'
services:
...
mysql:
image: mysql:8
volumes:
- ./data/db:/var/lib/mysql:delegated
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
node:
build: ./js
(Note that I've used the short syntax for build: to use the default Dockerfile in the context directory; I've removed unnecessary container_name: and networks: options, using the Compose-provided default network; and I've removed the volumes: that overwrite the image's content. Make sure ./js/Dockerfile has a CMD instruction that says how to start the container.)
I am trying to set up a local environment for web development (LAMP stack) using Docker.
All websites live in folder called Sites with this structure:
/Sites
-- site1.local
-- www
-- site2.local
-- www
For every website I need its own version of PHP and MySQL.
So far I was able to run one local website with this docker-compose.yml (uses php:7.1-apache):
version: "3"
services:
webserver:
build:
context: ./bin/webserver
container_name: 'sp-webserver'
restart: 'always'
ports:
- "80:80"
- "443:443"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
mysql:
build: ./bin/mysql
container_name: 'sp-mysql'
restart: 'always'
ports:
- "3306:3306"
volumes:
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: sp-demo
MYSQL_USER: sp-demo
MYSQL_PASSWORD: sp-demo
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'rb-phpmyadmin'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8080:80'
volumes:
- /sessions
redis:
container_name: 'rb-redis'
image: redis:latest
ports:
- "6379:6379"
The website is available at http://localhost:80
Questions:
1) How do I make it accesible by domain domain, for example, http://site1.local instead of http://localhost:80? I heard I need some Nginx Proxy for this (https://github.com/jwilder/nginx-proxy), but I can't understand how to set it up with Apache in my case.
2) How to set up the second website (http://site2.local) the same way to run it simultaneously? As far as I understand, I would need to change all ports (80, 443 and 3306), otherwise I will have a conflict when I run docker-compose up -d? Is it possible without changing ports?
Thanks for the answers!
I'm using Docker to work with php projects.
When I try to change a file of a project on my host machine, PhpStorm says
Could someone please help me to configure the permissions so I could work with the files of my project on my host machine. I'm using Ubuntu 18.04
docker-compose.yml:
version: "3.1"
services:
mysql:
image: mysql:8.0
container_name: symtest-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=symfony2
- MYSQL_PASSWORD=123
ports:
- "8084:3306"
webserver:
image: nginx:alpine
container_name: symtest-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8082:80"
php-fpm:
build: phpdocker/php-fpm
container_name: symtest-php-fpm
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
UPD: This problem appeared after I generated a new entity inside the docker using bin/console command.
I am runing a Symfony 3.4 application with docker, i need to upload a file and save it to /web/files. When i'm trying to do so i get an error:
Unable to create the "/home/docker/web/files/" directory
Note that i mounted the directory as Read-Write in cocker compose:
version: '2'
services:
front:
image: nginx
ports:
- "81:80"
links:
- "engine:engine"
- "db:db"
volumes:
- ".:/home/docker:ro"
- "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"
engine:
build: ./docker/engine/
volumes:
- ".:/home/docker:rw"
- "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
links:
- "db:db"
working_dir: "/home/docker"
db:
image: camptocamp/postgres:9.6
ports:
- "5433:5432"
environment:
- "POSTGRES_DB=pfe"
- "POSTGRES_PASSWORD=admin"
- "POSTGRES_USER=admin"
- "PGDATA=/var/lib/postgresql/data/pgdata"
I even created the directory files in /web, but its not working!
I create a separate container for my files, and just base it on an apache image. Then I use the volumes_from key to pass it into my php. Give something like this a try:
services:
apache:
build: ./build/httpd
links:
- php
ports:
- 80:80
- 443:443
volumes_from:
- app
php:
build: ./build/php
ports:
- 9000
- 9001
volumes_from:
- app
links:
- mariadb
- mail
app:
image: httpd:latest
volumes:
- ./:/var/www/html
command: "echo true"
I am working on a php docker application.Am facing an error while trying
docker-compose up command. Trying to connect a php application to mysql.
My docker compose file :-
version: '2'
services:
web:
container_name: modeloPHP5.4-Apache
build: .
ports:
— 8889:80
volumes:
— ./www:/var/www/html
links:
— db
db:
container_name: modeloMySQL
build:
context: ./
dockerfile: DockerfileDB
volumes:
— /var/lib/mysql
ports:
— 3307:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: db_test
Docker compose files are YAML files that require indentation, due to a wrong indentation in your compose file, Docker thinks that build is a service declaration. You've a similar question here and you can follow an example in Docker docs to check how the indentation works.
docker-compose file is using the YAML format, so you must check every space, line, new line and other syntax is correct in yaml format.
you can use yaml parser to help you to check docker-compose file.
version: '2'
services:
web:
container_name: modeloPHP5.4-Apache
build: .
ports:
- 8889:80
volumes:
- ./www:/var/www/html
links:
- db
db:
container_name: modeloMySQL
build:
context: ./
dockerfile: DockerfileDB
volumes:
- /var/lib/mysql
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: db_test