docker-compose with volumes - no files in project directory in continers - docker

I am trying to change my docker-compose to use volumes but my /application dir in containers is empty.
When i have config without volumes everything works fine:
volumes:
- .:/application
But when i use
volumes:
- code:/application
volumes:
code:
i get empty /application in containers.
Full docker-compose file:
version: "3.9"
services:
mariadb:
image: mariadb:10.5
container_name: youtube-playlist-mariadb
working_dir: /application
networks:
- backend
volumes:
- /var/lib/mysql/data:/var/lib/mysql
- /var/lib/mysql/logs:/var/log/mysqld.log
- /var/docker/mariadb/conf:/etc/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=database
- MYSQL_USER=root
- MYSQL_PASSWORD=password
ports:
- "3003:3306"
web:
image: nginx:alpine
container_name: youtube-playlist-web
working_dir: /application
networks:
- frontend
- backend
volumes:
- code:/application
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
php:
build: docker/php-fpm
container_name: youtube-playlist-php
working_dir: /application
networks:
- frontend
- backend
volumes:
- code:/application
node:
image: node:12.22.1
container_name: youtube-playlist-node
working_dir: /application
networks:
- frontend
- backend
volumes:
- code:/application
networks:
frontend:
backend:
volumes:
code:
x-mutagen:
sync:
defaults:
ignore:
vcs: true
code:
alpha: "."
beta: "volume://code"
mode: "two-way-resolved"
Edit: added mutagen config
Edit:
SOLUTION
I added this config to docker-compose
volumes:
code:
driver: local
driver_opts:
type: none
device: $PWD
o: bind

when you do what you are doing, you are just creating a volume where the content of the /application is going to be stored.
This is different to a bind-mount as you are doing in the first example (the one you say it's working). In this case, you are binding a directory (.) to /application.

Related

How i can mount code folder in Docker Volume

I'm new to Docker, after a few changes my app work flowless locally, but when I try to put it on the server things are different. On the server, I use Ubuntu+ Docker and Portainer for GUI.
i tried many configuration for volume settings and volume in services.
My docker-compose.yml
version: "3.8"
services:
# Application
app:
build:
context: ./docker/services/app
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- app-volume:/var/www
# Web Server
web:
build:
context: ./docker/services/web
dockerfile: web.dockerfile
working_dir: /var/www
volumes:
- app-volume:/var/www
ports:
- "80:80"
# Database
database:
image: mysql:8.0.25
volumes:
- db-volume:/var/lib/mysql
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
ports:
- "3306:3306"
# Database Management
pma:
image: phpmyadmin:5.1
environment:
- PMA_ARBITRARY=1
- PMA_HOST=${DB_HOST}
- PMA_USER=${DB_USERNAME}
- PMA_PASSWORD=${DB_PASSWORD}
- PMA_PORT=${DB_PORT}
depends_on:
- "database"
ports:
- "8888:80"
# Caching
redis:
image: redis:alpine
volumes:
- redis-volume:/data
ports:
- "6379:6379"
# Mailing Server
mailhog:
image: mailhog/mailhog:latest
logging:
driver: "none"
ports:
- "1025:1025"
- "8025:8025"
volumes:
app-volume:
driver: local
driver_opts:
type: none
o: bind
device: "./src"
db-volume:
redis-volume:
Laravel app is in src folder.
Tests that i tried
On Volume:driver_opt:device :
device: ./src
device: "./src"
device: "$PWD/src"
On Service: app/web:
volumes:
- "./src:/var/www"
- app-volume:/var/www
- ./src:/var/www
I don't understand why local is ok and o server is not.
Maybe some portainer settings? but what?

Docker-Compose build image and use its .env file which are stored in another directory

I have a docker-compose file which contains a bunch of services. To that docker-compose file, I want to add another service now. The other service files (including its .env) are stored in another folder. I tried to build it like I show you below, but it isnt working. Where do I go wrong?
The docker-compose.yml is contained in the directory nft-trading-service, the other dockerfile which I am trying to include in this docker-compose.yaml is in its own folder nft-asset-updater.
So the structure looks like this
root/nft-trading-server (holding docker-compose.yml)
root/nft-asset-updater (holding its own Dockerfile and .env)
version: "3"
services:
nftapi:
env_file:
- .env
build:
context: .
ports:
- '5000:5000'
depends_on:
- postgres
networks:
- postgres
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
asset_update_service:
env_file:
- .env
build:
context: ../nft-asset-updater
dockerfile: .
ports:
- '9000:9000'
depends_on:
- postgres
networks:
- postgres
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
postgres:
container_name: postgres
image: postgres:latest
ports:
- "5432:5432"
volumes:
- /data/postgres:/var/lib/postgresql/data
env_file:
- docker.env
networks:
- postgres
pgadmin:
links:
- postgres:postgres
container_name: pgadmin
image: dpage/pgadmin4
ports:
- "8080:80"
env_file:
- docker.env
networks:
- postgres
networks:
postgres:
driver: bridge

"Unable to find template" with Docker

I created a Symfony environment with Docker. I then included this file in my web project (skeleton website). But when I try to access my base.html.twig page located in a main folder from the controller, I get this error:
Unable to find template "main/base.html.twig" (looked into: /var/www/templates, /var/www/vendor/symfony/twig-bridge/Resources/views/Form).
How can I solve the problem? I have version 5 of Symfony.
Here is the content of my docker-compose file:
version: '3'
services:
php:
container_name: "php-fpm"
build:
context: ./php
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
volumes:
- ${APP_FOLDER}:/var/www
networks:
- dev
nginx:
container_name: "nginx"
build:
context: ./nginx
volumes:
- ${APP_FOLDER}:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log/nginx/
depends_on:
- php
ports:
- "80:80"
networks:
- dev
db:
image: mysql
container_name: "db"
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev
phpmyadmin:
image: phpmyadmin
container_name: "phpmyadmin"
restart: always
depends_on:
- db
ports:
- 8080:80
environment:
PMA_HOST: db
networks:
- dev
networks:
dev:
volumes:
db-data:
Your Docker Compose file needs to link local folders with Docker folders.
#docker-compose example
version: "3"
services:
web:
build: .
ports:
- "8080:80"
volumes:
- .:/var/www # Map local folder to Docker

Docker compose 3.1, communication between two docker-compose.yml

For past 3 days I have been trying to connect two docker containers generated by two separate docker-compose files.
I tried a lot of approaches none seem to be working. Currently after adding network to compose files, service with added network doesn't start. My goal is to access endpoint from another container.
Endpoint-API compose file:
version: "3.1"
networks:
test:
services:
mariadb:
image: mariadb:10.1
container_name: list-rest-api-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=list-api
- MYSQL_USER=list-api
- MYSQL_PASSWORD=root
ports:
- "8003:3306"
webserver:
image: nginx:stable
container_name: list-rest-api-webserver
working_dir: /application
volumes:
- .:/application
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8005:80"
networks:
- test
php-fpm:
build: docker/php-fpm
container_name: list-rest-api-php-fpm
working_dir: /application
volumes:
- .:/application
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Consumer compose file:
version: "3.1"
networks:
test:
services:
consumer-mariadb:
image: mariadb:10.1
container_name: consumer-service-mariadb
working_dir: /consumer
volumes:
- .:/consumer
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=consumer
- MYSQL_USER=consumer
- MYSQL_PASSWORD=root
ports:
- "8006:3306"
consumer-webserver:
image: nginx:stable
container_name: consumer-service-webserver
working_dir: /consumer
volumes:
- .:/consumer
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8011:80"
networks:
- test
consumer-php-fpm:
build: docker/php-fpm
container_name: consumer-service-php-fpm
working_dir: /consumer
volumes:
- .:/consumer
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Could someone tell me best way of accessing API container from within consumer? I'm loosing my mind on this one.
Your two
networks:
test:
don't refer to the same network, but they are independent and don't talk to each other.
What you could do is having an external and pre-existing network that both compose file can talk and share. You can do that with docker network create, and then refer to that in your compose files with
networks:
default:
external:
name: some-external-network-here

Docker composer and volume

I have generated a docker yml file with necessary images. I have placed index.php in the current directory which is required by nginx to display the page and when i run docker-compose up command, no files from my working directory detected in /application directory from container.
version: "2"
services:
memcached:
image: memcached:alpine
container_name: juzpay-docker-memcached
mysql:
image: mysql:8.0
container_name: juzpay-docker-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=juzpay_db
- MYSQL_USER=root
- MYSQL_PASSWORD=root123
ports:
- "8082:3306"
webserver:
image: nginx:alpine
container_name: juzpay-docker-webserver
working_dir: /application
volumes:
- ./dockerapp:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
php-fpm:
build: phpdocker/php-fpm
container_name: juzpay-docker-php-fpm
working_dir: /application
volumes:
- ./dockerapp:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini

Resources