Multiple WordPress sites with one shared DB using DockerCommunication between multiple docker-compose projectsDocker: trouble connecting to mysql, network issue?Shared volume within multiple docker containersDocker Compose - Share named volume between multiple containersdocker-compose: Sharing container between multiple projects by using the same container_nameWhy is Wordpress failing to connect to MySQL in this docker-compose app?How to update wordpress on dockerWordpress write-access when using Docker for WindowsERROR: In file '.docker-compose.yml', volume must be a mapping, not a string. - Docker with WordpressERROR: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection-Docker with Wordpress

Can't stopover at Sapporo when going from Asahikawa to Chitose airport?

How would one country purchase another?

What magic extends life or grants immortality?

Does norwegian.no airline overbook flights?

Average period of peer review process

Confirming resignation after resignation letter ripped up

Non-visual Computers - thoughts?

Sun setting in East!

Why is less being run unnecessarily by git?

Please help me identify the bold slashes between staves

how do you harvest carrots in creative mode

In an emergency, how do I find and share my position?

What is the history of the university asylum law?

Is it safe to remove the bottom chords of a series of garage roof trusses?

Notepad++ - How to find multiple values on the same line in any permutation

Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?

Fancy String Replace

Prove your innocence

Irish Snap: Variant Rules

Mathematical uses of string theory

Can you feel passing through the sound barrier in an F-16?

Avoiding racist tropes in fantasy

What does どうかと思う mean?

If all stars rotate, why was there a theory developed, that requires non-rotating stars?



Multiple WordPress sites with one shared DB using Docker


Communication between multiple docker-compose projectsDocker: trouble connecting to mysql, network issue?Shared volume within multiple docker containersDocker Compose - Share named volume between multiple containersdocker-compose: Sharing container between multiple projects by using the same container_nameWhy is Wordpress failing to connect to MySQL in this docker-compose app?How to update wordpress on dockerWordpress write-access when using Docker for WindowsERROR: In file '.docker-compose.yml', volume must be a mapping, not a string. - Docker with WordpressERROR: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection-Docker with Wordpress






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















I want to run multiple WordPress websites with one shared database using docker.



Is it possible to specify a database and set an appropriate volume to a certain sql file to initialize WordPress for each container in its docker-compose.yml file?




For example, I have three docker-compose.yml files for a shared container, siteA and siteB.



When I run docker-compose up in ./shared, two DBs will be created for the two sites (example_a and example_b).



And when I run docker-compose up in ./siteA, I want to change current DB to example_a, and initialize the site with a certain amount of data by sql volumed from ./siteA/mysql/setup.sql.



Same thing goes with siteB.



I know I can specify a database and volume like -
WORDPRESS_DB_NAME: example_a
and - ./db-data/mysql.dump.sql:/docker-entrypoint-initdb.d/install_wordpress.sql in mysql section in docker-compose.yml but I only have one shared mysql and cannot specify DB and volume for each site.




I have multiple docker-compose.yml files look something like below.



./shared/docker-compose.yml



version: "2"

services:

proxy:
image: jwilder/nginx-proxy
privileged: true
container_name: proxy
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
restart: always
logging:
options:
max-size: 5m
max-file: "10"

mysql:
image: mysql:5.7
container_name: mysql
command: >
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max-allowed-packet=128M
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=foobar
restart: always
volumes:
- db-data:/var/lib/mysql
- ./mysql/sql-setup.sql:/docker-entrypoint-initdb.d/sql-setup.sql # to create multiple databases (e.g. example_a, example_b)
logging:
options:
max-size: 5m
max-file: "10"

volumes:
db-data:
driver: local

networks:
default:
external:
name: shared


./siteA/docker-compose.yml



version: "2"

services:
example_a_wordpress:
image: wordpress
container_name: a.example
environment:
WORDPRESS_DB_NAME=example_a
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: a.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared


./siteB/docker-compose.yml



version: "2"

services:
example_b_wordpress:
image: wordpress
container_name: b.example
environment:
WORDPRESS_DB_NAME=example_b
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: b.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared









share|improve this question



















  • 2





    I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

    – cannydare
    Nov 21 '17 at 14:59






  • 1





    In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

    – Pascal Martineau
    Nov 22 '17 at 16:58











  • Did you ever solve this? :)

    – Henning Hall
    Sep 30 '18 at 12:34











  • By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

    – Bas van Dijk
    Feb 8 at 16:08

















7















I want to run multiple WordPress websites with one shared database using docker.



Is it possible to specify a database and set an appropriate volume to a certain sql file to initialize WordPress for each container in its docker-compose.yml file?




For example, I have three docker-compose.yml files for a shared container, siteA and siteB.



When I run docker-compose up in ./shared, two DBs will be created for the two sites (example_a and example_b).



And when I run docker-compose up in ./siteA, I want to change current DB to example_a, and initialize the site with a certain amount of data by sql volumed from ./siteA/mysql/setup.sql.



Same thing goes with siteB.



I know I can specify a database and volume like -
WORDPRESS_DB_NAME: example_a
and - ./db-data/mysql.dump.sql:/docker-entrypoint-initdb.d/install_wordpress.sql in mysql section in docker-compose.yml but I only have one shared mysql and cannot specify DB and volume for each site.




I have multiple docker-compose.yml files look something like below.



./shared/docker-compose.yml



version: "2"

services:

proxy:
image: jwilder/nginx-proxy
privileged: true
container_name: proxy
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
restart: always
logging:
options:
max-size: 5m
max-file: "10"

mysql:
image: mysql:5.7
container_name: mysql
command: >
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max-allowed-packet=128M
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=foobar
restart: always
volumes:
- db-data:/var/lib/mysql
- ./mysql/sql-setup.sql:/docker-entrypoint-initdb.d/sql-setup.sql # to create multiple databases (e.g. example_a, example_b)
logging:
options:
max-size: 5m
max-file: "10"

volumes:
db-data:
driver: local

networks:
default:
external:
name: shared


./siteA/docker-compose.yml



version: "2"

services:
example_a_wordpress:
image: wordpress
container_name: a.example
environment:
WORDPRESS_DB_NAME=example_a
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: a.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared


./siteB/docker-compose.yml



version: "2"

services:
example_b_wordpress:
image: wordpress
container_name: b.example
environment:
WORDPRESS_DB_NAME=example_b
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: b.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared









share|improve this question



















  • 2





    I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

    – cannydare
    Nov 21 '17 at 14:59






  • 1





    In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

    – Pascal Martineau
    Nov 22 '17 at 16:58











  • Did you ever solve this? :)

    – Henning Hall
    Sep 30 '18 at 12:34











  • By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

    – Bas van Dijk
    Feb 8 at 16:08













7












7








7


3






I want to run multiple WordPress websites with one shared database using docker.



Is it possible to specify a database and set an appropriate volume to a certain sql file to initialize WordPress for each container in its docker-compose.yml file?




For example, I have three docker-compose.yml files for a shared container, siteA and siteB.



When I run docker-compose up in ./shared, two DBs will be created for the two sites (example_a and example_b).



And when I run docker-compose up in ./siteA, I want to change current DB to example_a, and initialize the site with a certain amount of data by sql volumed from ./siteA/mysql/setup.sql.



Same thing goes with siteB.



I know I can specify a database and volume like -
WORDPRESS_DB_NAME: example_a
and - ./db-data/mysql.dump.sql:/docker-entrypoint-initdb.d/install_wordpress.sql in mysql section in docker-compose.yml but I only have one shared mysql and cannot specify DB and volume for each site.




I have multiple docker-compose.yml files look something like below.



./shared/docker-compose.yml



version: "2"

services:

proxy:
image: jwilder/nginx-proxy
privileged: true
container_name: proxy
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
restart: always
logging:
options:
max-size: 5m
max-file: "10"

mysql:
image: mysql:5.7
container_name: mysql
command: >
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max-allowed-packet=128M
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=foobar
restart: always
volumes:
- db-data:/var/lib/mysql
- ./mysql/sql-setup.sql:/docker-entrypoint-initdb.d/sql-setup.sql # to create multiple databases (e.g. example_a, example_b)
logging:
options:
max-size: 5m
max-file: "10"

volumes:
db-data:
driver: local

networks:
default:
external:
name: shared


./siteA/docker-compose.yml



version: "2"

services:
example_a_wordpress:
image: wordpress
container_name: a.example
environment:
WORDPRESS_DB_NAME=example_a
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: a.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared


./siteB/docker-compose.yml



version: "2"

services:
example_b_wordpress:
image: wordpress
container_name: b.example
environment:
WORDPRESS_DB_NAME=example_b
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: b.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared









share|improve this question














I want to run multiple WordPress websites with one shared database using docker.



Is it possible to specify a database and set an appropriate volume to a certain sql file to initialize WordPress for each container in its docker-compose.yml file?




For example, I have three docker-compose.yml files for a shared container, siteA and siteB.



When I run docker-compose up in ./shared, two DBs will be created for the two sites (example_a and example_b).



And when I run docker-compose up in ./siteA, I want to change current DB to example_a, and initialize the site with a certain amount of data by sql volumed from ./siteA/mysql/setup.sql.



Same thing goes with siteB.



I know I can specify a database and volume like -
WORDPRESS_DB_NAME: example_a
and - ./db-data/mysql.dump.sql:/docker-entrypoint-initdb.d/install_wordpress.sql in mysql section in docker-compose.yml but I only have one shared mysql and cannot specify DB and volume for each site.




I have multiple docker-compose.yml files look something like below.



./shared/docker-compose.yml



version: "2"

services:

proxy:
image: jwilder/nginx-proxy
privileged: true
container_name: proxy
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
restart: always
logging:
options:
max-size: 5m
max-file: "10"

mysql:
image: mysql:5.7
container_name: mysql
command: >
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--max-allowed-packet=128M
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=foobar
restart: always
volumes:
- db-data:/var/lib/mysql
- ./mysql/sql-setup.sql:/docker-entrypoint-initdb.d/sql-setup.sql # to create multiple databases (e.g. example_a, example_b)
logging:
options:
max-size: 5m
max-file: "10"

volumes:
db-data:
driver: local

networks:
default:
external:
name: shared


./siteA/docker-compose.yml



version: "2"

services:
example_a_wordpress:
image: wordpress
container_name: a.example
environment:
WORDPRESS_DB_NAME=example_a
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: a.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared


./siteB/docker-compose.yml



version: "2"

services:
example_b_wordpress:
image: wordpress
container_name: b.example
environment:
WORDPRESS_DB_NAME=example_b
WORDPRESS_DB_PASSWORD=foobar
VIRTUAL_HOST: b.example.dev
external_links:
- mysql
restart: always
volumes:
- ./dist/theme:/var/www/html/wp-content/themes/main
- ./dist/assets:/var/www/html/assets
logging:
options:
max-size: 5m
max-file: "10"

networks:
default:
external:
name: shared






mysql wordpress docker docker-compose dockerfile






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 11 '17 at 5:32









Ryo IkarashiRyo Ikarashi

681 silver badge9 bronze badges




681 silver badge9 bronze badges










  • 2





    I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

    – cannydare
    Nov 21 '17 at 14:59






  • 1





    In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

    – Pascal Martineau
    Nov 22 '17 at 16:58











  • Did you ever solve this? :)

    – Henning Hall
    Sep 30 '18 at 12:34











  • By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

    – Bas van Dijk
    Feb 8 at 16:08












  • 2





    I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

    – cannydare
    Nov 21 '17 at 14:59






  • 1





    In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

    – Pascal Martineau
    Nov 22 '17 at 16:58











  • Did you ever solve this? :)

    – Henning Hall
    Sep 30 '18 at 12:34











  • By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

    – Bas van Dijk
    Feb 8 at 16:08







2




2





I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

– cannydare
Nov 21 '17 at 14:59





I think you're over-complicating this. You should look into Wordpress Multisite, which does pretty much everything you need. premium.wpmudev.org/blog/ultimate-guide-multisite

– cannydare
Nov 21 '17 at 14:59




1




1





In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

– Pascal Martineau
Nov 22 '17 at 16:58





In addition to sharing the MySQL container, you could also share an Apache2/PHP container instead of using multiple containers with the official wordpress image.

– Pascal Martineau
Nov 22 '17 at 16:58













Did you ever solve this? :)

– Henning Hall
Sep 30 '18 at 12:34





Did you ever solve this? :)

– Henning Hall
Sep 30 '18 at 12:34













By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

– Bas van Dijk
Feb 8 at 16:08





By using different prefixes you could store everything in one db. Don't get how this would be something you would really want tho.

– Bas van Dijk
Feb 8 at 16:08












1 Answer
1






active

oldest

votes


















0















Did you try setting up table prefix in wp_config.php



$table_prefix = 'yourcustomname_';



This should resolve the issue with one DB connection on both sites..






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43337459%2fmultiple-wordpress-sites-with-one-shared-db-using-docker%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    Did you try setting up table prefix in wp_config.php



    $table_prefix = 'yourcustomname_';



    This should resolve the issue with one DB connection on both sites..






    share|improve this answer





























      0















      Did you try setting up table prefix in wp_config.php



      $table_prefix = 'yourcustomname_';



      This should resolve the issue with one DB connection on both sites..






      share|improve this answer



























        0














        0










        0









        Did you try setting up table prefix in wp_config.php



        $table_prefix = 'yourcustomname_';



        This should resolve the issue with one DB connection on both sites..






        share|improve this answer













        Did you try setting up table prefix in wp_config.php



        $table_prefix = 'yourcustomname_';



        This should resolve the issue with one DB connection on both sites..







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 7 at 1:14









        Ganesh ChandrasekaranGanesh Chandrasekaran

        6272 silver badges8 bronze badges




        6272 silver badges8 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43337459%2fmultiple-wordpress-sites-with-one-shared-db-using-docker%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현