2

I come here because I develop an app with Symfony3. And I've some questions about the deployment of the app. Actually I use docker-compose:

version: '2'

services:
    nginx:
        build: ./docker/nginx/
        ports:
            - 8081:80
        volumes:
            - .:/home/docker:ro
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
            - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
        networks:
            - default

    php:
        build: ./docker/php/
        volumes:
            - .:/home/docker:rw
            - ./docker/php/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro
        working_dir: /home/docker
        networks:
            - default
        dns_search:
            - php

    db:
        image: mariadb:latest
        ports:
            - 3307:3306
        environment:
            - MYSQL_ROOT_PASSWORD=collectionManager
            - MYSQL_USER=collectionManager
            - MYSQL_PASSWORD=collectionManager
            - MYSQL_DATABASE=collectionManager
        volumes:
            - mariadb_data:/var/lib/mysql
        networks:
            - default
        dns_search:
            - db

    search:
        build: ./docker/search/
        ports:
            - 9200:9200
            - 9300:9300
        volumes:
            - elasticsearch_data:/usr/share/elasticsearch/data
        networks:
            - default
        dns_search:
            - search

volumes:
    mariadb_data:
        driver: local
    elasticsearch_data:
        driver: local

networks:
    default:

nginx is clear, engine is PHP-FPM with some extensions and composer, db is MariaDB, and search ElasticSearch with some plugins.

Before I don't use Docker and to deploy I used Megallanes or Deployer, when I want to deploy webapp.

With Docker I can use the docker-compose file and recreate images and container on the server, I also can save my containers in images and in tar archive and load it on the server. It's okay for nginx, and php-fpm, but what about elasticsearch and the db ? Because I need to keep data in for future update of the code. Then when I deploy the code I need to execute a Doctrine Migration and maybe some commands, and Deployer do it perfectly with some other interresting things. And how I deploy the code with Docker ? Can we use both ? Deployer for code and Docker for services ?

Thanks a lot for your help.

1 Answer 1

2

First of all , Please try using user-defined networks, they have additional features vs legacy linking like Embedded DNS. Meaning you can call other containers on the same network with their names in your applications. Containers on a User defined network are isolate from containers on another User defined network.

To create a user defined network:

docker network create --driver bridge <networkname>

Dockerfile to use user defined network example:

search:
    restart: unless-stopped
    build: ./docker/search/
    ports:
        - "9200:9200"
        - "9300:9300"
    networks:
        - <networkname>

Second: I noticed you didnt use data volumes for you DB and ElasticSearch. You need to mount volumes at certain points to keep your persistant data.

Third: When you export your containers it wont contain mounted volumes. You need to back up volume data and migrate it manually.

To backup volume data:

docker run --rm --volumes-from db -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata

The above command will create a container, mounts volumes from DB container and mounts current directory in container as /backup , uses ubuntu image and tar command to create a backup of /dbdata in container (consider changing this to your dbdirectory) in the /backup that is mounted from your docker hosts). after the operation completes the transient container will be removed (ubuntu container we used for creating the backup with --rm switch).

To restore:

You copy the tar archive to the remote location and create your container with empty mounted volume. then extract the tar archive in that volume using the following command.

docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"
Sign up to request clarification or add additional context in comments.

8 Comments

Hi, thanks for your help, I've do a volume mount for ElasticSearch and Mariadb. But I don't understand the first point, user defined networks ?
Edited the answer with more info.
I've edit my code and use networks, and volumes. But I don't really know what to do with my source code :/
Cool, Now you should mount your source code to nginx document root. Look at your nginx config. find the document root, then mount your source code directory to nginx container like what you did with nginx.conf file.
Yes I do it in development, the when I edit my code it directly used. But I search a method to deploy it in production. (just test, not really production yest). But I read somewhere the source code of the project may be in a container, some says the opposite.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.