dockerfile - Docker compose yml inheritance -


there 2 tasks: run app container, run same deploy-app container. differences them, example, deploy container not have port sharing.

so, made configs tasks...

./dockerfiles/base.yml:

app:     net: docker_internal_net     environment:         application_server: "docker" 

./dockerfiles/base.run.yml:

app:     container_name: project-app     # set build context project root     build: ..     volumes:         - /var/log/project/nginx:/var/log/nginx         - /var/log/project/php-fpm:/var/log/php5-fpm         - ..:/var/www/project 

./dockerfiles/dev/run.yml:

app:     dockerfile: ./dockerfiles/dev/run-app/dockerfile     ports:         - "80:80"         - "22:22"     environment:         dev_ssh_pubkey: "$ssh_public_key"         application_platform: "dev" 

./dockerfiles/dev/build.yml:

app:     container_name: project-app-deploy     # set build context project root     build: ../..     dockerfile: ./dockerfiles/dev/build-app/dockerfile     environment:         application_platform: "dev"     volumes:         - ../..:/var/www/project 

so can tun app container this:

$ docker-compose -f ./dockerfiles/base.yml -f ./dockerfiles/base.run.yml -f ./dockerfiles/dev/run.yml -d app creating project-app  $ docker ps container id        image               command                  created             status              ports                                        names dae45f3f2c42        dockerfiles_app     "/sbin/my_init"          2 seconds ago       1 seconds        0.0.0.0:2223->22/tcp, 0.0.0.0:8081->80/tcp   project-app 

everything okay. if trying run deploy-app container, receive message:

$ docker-compose -f ./dockerfiles/base.yml -f ./dockerfiles/dev/build.yml -d app recreating project-app warning: service "app" using volume "/var/www/project" previous container. host mapping ".." has no effect. remove existing containers (with `docker-compose rm app`) use host volume mapping.  $ docker ps container id        image               command                  created             status              ports               names 53059702c09b        dockerfiles_app     "/sbin/my_init"          6 seconds ago       4 seconds        22/tcp, 80/tcp      project-app-deploy 

this because both of them shared 1 local directory? why can run deploy-app container manually without docker-compose?

$ docker run -d --net docker_internal_net -e application_server=docker -e application_platform=dev --name project-app-deploy -v ..:/var/www/project mybaseimage 86439874b8df561f529fde0d1e31824d70dc7e2a2377cd529331a2d7fcb00467  $ docker ps container id        image               command                  created             status              ports                                        names 86439874b8df        mybaseimage         "/sbin/my_init"          4 seconds ago       3 seconds        22/tcp, 80/tcp                               project-app-deploy 40641f02a09b        dockerfiles_app     "/sbin/my_init"          2 minutes ago       2 minutes        0.0.0.0:2223->22/tcp, 0.0.0.0:8081->80/tcp   project-app 

i've solved problem extend command in way:

1) making changes ./dockerfiles/dev/build.yml file:

deploy-app:     extends:         file: ../base.yml         service: app     container_name: project-app-deploy     # set build context project root     build: ../..     dockerfile: ./dockerfiles/dev/build-app/dockerfile     environment:         application_platform: "dev"     volumes:         - ../..:/var/www/project 

2) run deploy app container so:

$ docker-compose -f ./dockerfiles/dev/build.yml -d deploy-app building deploy-app ... built 74750fe274c6 creating lovetime-app-deploy  $ docker ps container id        image               command                  created             status              ports                                        names 9bb2af79ffaa        dev_deploy-app      "/sbin/my_init"          5 seconds ago       4 seconds        22/tcp, 80/tcp                               project-app-deploy 812b8824f1f0        dockerfiles_app     "/sbin/my_init"          3 minutes ago       3 minutes        0.0.0.0:2223->22/tcp, 0.0.0.0:8081->80/tcp   project-app  $ docker inspect -f '{{ .mounts }}' project-app-deploy [{ ...... /var/www/project  rw true}] 

Comments