Access Files From Another Docker Container - Same Network - docker

I need help. I have an expressjs REST API that uplodas files using multer running in a container using docker-compose, and another front end app on another container. How can i access the uploaded files from the front end?
version: '2'
services:
api:
container_name: "api"
restart: always
build:
context: ./api
ports:
- "8383:8383"
environment:
- test=testvalue
networks:
- pms
app:
container_name: "app"
restart: always
build:
context: ./app
ports:
- "7777:80"
environment:
- test=testvalue
networks:
- pms
networks:
pms:

Related

"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

Error while trying to convert compose file to kubernetes manifest

I am trying to convert a docker compose file to a kubernetes manifest for deployment and after installing the Kompose on my system, I used the command kompose convert -f docker-compose.yml for the conversion process but it is not working. The error response is ←[31mFATA←[0m services.web.stdin_open must be a boolean.
The docker-compose file is shown thus:
version: '3'
services:
# Backend / Database
database:
image: database
build: ../backend/database
volumes:
- ../backend/database:/data/db
restart: always
networks:
- back
# Backend / API
api:
image: api
build: ../backend/api
volumes:
- ../backend/api/public:/user/src/app/public
restart: always
ports:
- "8084:8080"
depends_on:
- database
networks:
- front
- back
# Backend / Proxy
proxy:
image: nginx
volumes:
- ../backend/proxy/nginx.conf:/etc/nginx/conf.d/proxy.conf
restart: always
ports:
- "80:80"
- "443:443"
depends_on:
- database
- api
networks:
- front
- docker-network
# Frontend / App / Web
web:
image: web
stdin_open: "true"
build: ../frontend/app/web
restart: always
ports:
- "3000:3000"
depends_on:
- api
networks:
- front
networks:
front:
driver: bridge
back:
driver: bridge
docker-network:
driver: bridge
Please I'd like help on how I can avoid this error and build the manifest file. I am running this on a windows machine. Also a screenshot of the error is shown in the image attached.
screenshot of error
Many Thanks.
Change stdin_open to true instead of ”true”
services:
web:
stdin_open: true

best practice for sshfs via docker-compose to other computer but don't want to expose port publicly

I want to mount a volume in docker via sshfs to another computer that's ideally on my local network that my docker host is on. The problem is that it can't see the host if I try to ssh into via the usual 192.168.. ip. The other option I have is to expose the machines SSH port to the internet, but I know that is bad practice, so i'm wondering if there's any other way to do this? Can I connect via a VPN of some sort or can I make the docker volume reach my local network on my host?
Ideally i'm just looking for some guidance.
version: "3"
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
sshfs:
driver: vieux/sshfs:latest
driver_opts:
sshcmd: "secretuser#192.168.0.114:/home"
password: "secretpassword"
allow_other: ""
services:
nginx:
image: nginx:alpine
container_name: nx01
ports:
- "80:8000"
- "443:443"
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
depends_on:
- web
frontend:
container_name: frontend-vue
build:
context: .
dockerfile: compose/frontend/Dockerfile
volumes:
- './frontend:/frontend'
- '/frontend/node_modules'
ports:
- '8081:8080'
web:
build:
context: .
dockerfile: compose/django/Dockerfile
container_name: dx01
depends_on:
- db
- redis
volumes:
- ./src:/src
- sshfs:/src/mount
expose:
- "8000"
env_file:
- ./.envs/.django
db:
build:
context: .
dockerfile: compose/postgres/Dockerfile
container_name: px01
env_file:
- ./.envs/.postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
redis:
image: redis:latest
container_name: rs01
ports:
- "127.0.0.1:6379:6379"

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

Adding an external network makes MySQL database unreachable

I'm having some problems with a docker-compose file and haven't been able to figure out why.
This is the file:
version: '3'
services:
db:
image: mysql:8.0.0
environment:
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: ******
volumes:
- /opt/mysql_auth:/var/lib/mysql
restart: always
auth:
image: authdotnetcore
build:
context: .
dockerfile: Auth/Dockerfile
depends_on:
- db
restart: always
networks:
- web
networks:
web:
external: true
The auth service is a ASP.NET Core application which connect to the MySQL database using db as server on the appsettings. The compose file works fine if I remove the external web network, but when I add it I get a: Unable to connect to any of the specified MySQL hosts.
It should work because the compose default network linking the containers is still created.
As per the docker-compose documentation, Please find more details Here.
DB service was missing the networks section:
version: '3'
services:
db:
image: 'mysql:8.0.0'
environment:
MYSQL_ROOT_PASSWORD: null
MYSQL_DATABASE: null
volumes:
- '/opt/mysql_auth:/var/lib/mysql'
restart: always
networks:
- web
auth:
image: authdotnetcore
build:
context: .
dockerfile: Auth/Dockerfile
depends_on:
- db
restart: always
links:
- db
networks:
- web
networks:
web:
external: true

Resources