Proper docker-compose for microservices


#1

can someone port my docker-compose to a proper one for use with resin?
yaml is on the same folder as laravel project and contains an nginx.conf file
i prefer to use only docker-compose and not Dockerfiles with no specific reason

here is my yaml:

version: '3.2'
services:
 web:
  image: nginx:mainline-alpine
  ports:
    - "8080:80"
  volumes:
    - type: bind
      source: .
      target: /project
    - type: bind
      source: ./nginx.conf
      target: /etc/nginx/conf.d/default.conf
  links:
    - php

 php:
  image: php:7-fpm-alpine
  volumes:
    - type: bind
      source: .
      target: /project
  links:
    - db

 db:
  image: mariadb:latest
  environment:
    MYSQL_ROOT_PASSWORD: rootpass
    MYSQL_DATABASE: dbname
    MYSQL_USER: dbuser
    MYSQL_PASSWORD: dbpass

it works on a debian base docker host
Thanks in advance
Nikos


#4

Hi,
We currently only support the short syntax and named volumes. Can you try changing that part and let us know whether it works for your use case?

Let me share with you a link to our related documentation page and a link to the docker compose docs.

See: https://docs.resin.io/reference/supervisor/docker-compose/#docker-compose-yml-fields
See: https://docs.docker.com/compose/compose-file/#short-syntax-3


#6

ok i changed my volumes to short syntax
php:
image: php:7-fpm-alpine
volumes:
- ./:/project
links:
- db

and now when i push to resin i get this message
[Error] Could not parse compose file
[Error] Missing volume definition for ‘./’
[Error] Not deploying release.


#7

Hi again,
I just realized that I should have pointed to you to the v2 docker-compose.yml docs where the first part should be a volume and ./ isn’t allowed.
See: https://docs.docker.com/compose/compose-file/compose-file-v2/#short-syntax

Try using something like this:

version: '2'
services:
  service1:
    build: ./service1
    expose:
      - "8080"
    volumes:
      - data-volume:/usr/src/app/tmp
    links:
      - db

volumes:
  data-volume:
  db:

see: https://docs.docker.com/compose/compose-file/compose-file-v2/#volume-configuration-reference


#9

i have banging my head reading the docs
where do i specify the source of the data-volume ?
what wil be mounted on the /usr/src/app/tmp on the cointainer?
docker will generate a random folder and mount this folder?
i want to mount my project in the cointaner


#10

Hi @paranic,

Keep in mind that whatever you build on resin will be deployed to the devices by means of the resin API, so what will actually get to the device will be the docker-compose (in a modified version for the supervisor on the device to understand) with the corresponding docker images.

This means that your local development folder will not exist there, so you can’t bind mount your development folder into the container.

So I understand you prefer not to have Dockerfiles with no specific reason, but here the reason is that the way the code gets deployed to your fleet is via images, and therefore you need to use a Dockerfile rather than mounts.

Hope this clarifies a bit!


#12

Hi @pcarranzav

so to get it straight
i have to build a custom container witch will include my project files?
and my project will reside inside the container and then be pulled by my device?


#13

Hi @paranic,

That’s absolutely correct, you’ll need to make your project files available via a container (although there’s nothing stopping you copying them to a named volume on startup and then sharing them with other containers).


#14

ok thanks for the clearing this up.
i think this was not obvious on the documentation and on the examples on github but i guess i am not so experienced in docker to figure this out by my self.