I've run a container with docker-compose following this Docker page, that use this docker-compose.yml file:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
The point is, I want to connect to a local database and needs to change the default DB connection from MySQL to a PostgreSQL DB. I've used the docker environment variables, setting the WORDPRESS_DB_HOST/USER/PASSWORD/NAME in wordpress section, but in the end Wordpress states that connection can't be established.
And I want to create my own Wordpress theme but I don't know where the folder is created to put the theme files there.
Any help will be grateful. Thanks in advance.
If you don't already have the Postgres Docker Image running (assuming you're wanting to also run that as a Docker image, and not installed directly on your machine), you'll need to get it all set up first so you know all of it's settings that you'll need.
After that, you'll need to edit your dockerfile to look something to this:
version: '3.3'
services:
db:
image: postgres
volumes:
- db_data:/var/lib/postgres
restart: always
environment:
<the environment vars for postres>
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Regarding where to place your custom theme(s), it should be in your my_wordpress_wordpress_1 volume (or whichever one it automatically created. I don't have WP installed in a docker machine so I don't know firsthand how they place the data in that volume, but typically WP's file tree looks like this: wp-content\themes
Related
I would like to run my Wordpress site on Docker, and I want to connect the Wordpress database to another container which have only the databases of all my sites.
For doing so, I've created a LAMP container using the following docker-compose.yml:
version: "3"
services:
web:
image: webdevops/php-apache:alpine-php7
ports:
- "4500:80"
volumes:
- ./www:/app
- ./uploads.ini:/opt/docker/etc/php/php.ini
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "8088:80"
as you can see I've installed Apache as service using the webdevops image, this return the following:
Then, I've created a new container which have the Wordpress instance:
version: '3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./wp/wp-content:/var/www/html/wp-content
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: lamp_db_1:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: root
volumes:
dbdata:
wp-content:
as you can see I mount the wp-content folder since I already have a Wordpress installation with plugins and media... then I tried to connect this container to lamp_db_1 container but when I run this using:
docker-compose up --build
I get:
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
what I did wrong?
How can I connect the wordpress container to the LAMP container?
You can specify a custom network in your LAMP stack and have your Wordpress stack and other containers defined in other Compose files use this network by using network.external parameter in Compose.
Being on the same network, you'll be able to join your lamp_db container using it's container name as hostname.
A complete example:
docker-compose.yml for LAMP stack:
version: '3.5'
services:
db:
# This will be the hostname for your DB container on the network
container_name: lamp_db
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
# Have db container join our db network
networks:
- db_network
# Ensure our custom network is managed by this stack
networks:
db_network:
name: db_network
docker-compose.yml for Wordpress stack:
version: '3.5'
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
environment:
# Name of the db container
WORDPRESS_DB_HOST: lamp_db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: root
# Have wordpress container join our db network
networks:
- db_network
# Declare db_network as external with it's name
# Network won't be created by this stack but must exists before running
# See https://docs.docker.com/compose/compose-file/#external-1
networks:
db_network:
external: true
name: db_network
And a generic example any service that would need to use our database:
version: '3.5'
services:
some_container:
image: some-image:latest
# Have this container join our db network
networks:
- db_network
# Note: make sure to reference db container by it's hostname lamp_db
networks:
db_network:
external: true
name: db_network
Notes:
db_network is managed via LAMP stack. When uping the LAMP stack, Docker Compose will ensure this network is created. Other stacks using this network should declare it as external: true with it's name
You'll need version: '3.5' or more to be able to use network.name config
It seems the reason you are running into this issue is due to the fact that you have two separate services. One contains your LAMP stack and the other contains your wordpress image.
When you run docker-compose it sets up a single network for your app. Thus your wordpress image isn't on the same network as your LAMP stack.
You can add your wordpress container to your LAMP docker-compose.yml file such as
version: "3"
services:
web:
image: webdevops/php-apache:alpine-php7
ports:
- "4500:80"
volumes:
- ./www:/app
- ./uploads.ini:/opt/docker/etc/php/php.ini
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "8088:80"
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./wp/wp-content:/var/www/html/wp-content
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: root
volumes:
dbdata:
wp-content:
And unless you are doing something specific with your php-apache image you can actually remove it at this point.
Another approach you could take if you do not want everything in the same docker-compose file is that you can manually define the networks and get your containers to join them. The answers on this question show how to do that fairly easily.
currently, I am working a lot with WordPress and for every project, my company wants different environments. So first of all we have our development environment which is running on our own server. Then there is the staging environment on the client's server and also the live(production) environment.
Also, there is the local environment in which every
participant developer is working on whatever features.
Since this is always a time-consuming hustle, I would love to use Docker to make things more straight forward.
So I set up my local environment with a docker-compose and create a MySql,WordPress and phpMyAdmin container.
With a shell script, I add a WordPress-theme and the Plugins from our private Gitlab repository as a submodule followed by the docker-compose up -d.
After all the containers are up and running I wait for a connection to the MySql-Database and then feed it with my backup.sql file.
That's all working fine so far...
version: '3.8'
volumes:
wp-content: {}
mysql-backup: {}
networks:
wp-back:
services:
db:
build:
context: .
dockerfile: Dockerfile-mysql
container_name: mysql-cont
volumes: ['mysql-backup:/root']
environment:
MYSQL_ROOT_PASSWORD: rootPassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wp-user
MYSQL_PASSWORD: wp-pass
ports:
- 8889:3306
networks:
- wp-back
restart: always
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
container_name: pma-cont
environment:
PMA_HOST: db
MYSQL_USER: wp-user
MYSQL_PASSWORD: wp-pass
MYSQL_ROOT_PASSWORD: rootPassword
ports:
- 3001:80
restart: always
networks:
- wp-back
wordpress:
depends_on:
- db
container_name: wp-cont
build:
context: .
dockerfile: Dockerfile-wordpress
ports:
- 8000:80
- 443:443
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp-user
WORDPRESS_DB_PASSWORD: wp-pass
volumes: ['./wp-content:/var/www/html/wp-content']
networks:
- wp-back
restart: always
But regarding my needs with the 3 different environments, I am struggling with a setup where I can easily take everything that I created local and put it on the other 2 servers (dev & staging/live)
Because I always have the theme and the backup.sql in my docker volume, I somehow need to share that with other developers and the servers. I mean for the WordPress theme I could just work with pulling it from the project's private GitLab repository.
But what to do with the .sql file?
Where is the best place to put it?
Should I put Dockerfile, wp-content and backup.sql into one single repository for the project? It's getting pretty heavy then
Furthermore, let's say after a year I want to be able to easily set up the project in my local environment with the MySQL-database and WordPress uploads from the live environment. But I don't find a solution.
I appreciate any kind of brainstorming, ideas, help or links.
Cheers
I have been using the following docker-compose.yml to build a WordPress environment. Everything has been working fine, except when I attempt to use PHP function easter_date() I receive an undefined function error.
Could anyone explain to me what I need to add to the YML file in order to include the PHP easter_date() extension?
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./data:/docker-entrypoint-initdb.d # This will import DB data from an sql file in your /data folder
- ./data/migrate.sql:/docker-entrypoint-initdb.d/migrate.sql # run sql commands in migrate.sql to update site urls in DB
restart: always
ports:
- "3400:3306" # mapping our ports for networking
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8080:80"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: wordpress
DOCKER_COMPOSE_YML_LOCATION: wordpress
container_name: wp_phpmyadmin
wordpress:
build:
context: .
depends_on:
- db
image: wordpress:latest
ports:
- "3500:80" # mapping our ports for networking
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
WORDPRESS_MEMORY_LIMIT: 256MB
working_dir: /var/www/html
volumes: # this is where we tell Docker what to pay attention to
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini # create custom uploads.ini which has an increased upload file size limit, memory etc.
volumes:
db_data: {}
I have attempted to include PHP extensions by inserting the following two lines:
php: #https://stackoverflow.com/questions/46401966/install-packages-from-docker-compose-yml-into-docker-container
build: './docker/php'
And then created a Dockerfile inside ./docker/php with
FROM php:7.1-fpm
RUN docker-php-ext-install calendar && docker-php-ext-configure calendar
But I receive ERROR: Cannot locate specified Dockerfile: Dockerfile when I run docker-compose build
I have installed laradoc as per documentation but I am unable to login phpmyadmin.
here is my docker-compose.yaml file:
phpmyadmin:
build: ./phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=${PMA_USER}
- MYSQL_PASSWORD=${PMA_PASSWORD}
- MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
ports:
- "${PMA_PORT}:80"
depends_on:
- "${PMA_DB_ENGINE}"
networks:
- frontend
- backend
and here is .env file
PMA_DB_ENGINE=mysql
PMA_USER=default
PMA_PASSWORD=secret
PMA_ROOT_PASSWORD=secret
PMA_PORT=8080
Difficult to reproduce the error from the given info but this small setup works so maybe you can find what went wrong?
First bring your existing stack down and delete dangling volumes:
$ docker-compose down
$ docker volume prune
Start the following docker-compose.yaml:
version: '3.1'
services:
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=${PMA_USER}
- MYSQL_PASSWORD=${PMA_PASSWORD}
- MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
ports:
- "${PMA_PORT}:80"
depends_on:
- "${PMA_DB_ENGINE}"
networks:
- frontend
- backend
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: db
MYSQL_USER: default
MYSQL_PASSWORD: secret
networks:
- frontend
- backend
networks:
frontend:
backend:
info (I had to use mysql5.7 otherwise I was facing this bug:
docker-compose up -d
Creating network "test_frontend" with the default driver
Creating network "test_backend" with the default driver
Creating test_mysql_1 ... done
Creating test_phpmyadmin_1 ... done
I know I'm a bit 'messing' with the syntax + you can use the env vars too for mysql but I had to be quick.
I want to load an existing Drupal site with all his dependencies in a freshly installed Drupal environment.
Most of the websites are based on Drupal 7.x and PHP 5.x.
I already created a environment using Docker (Drupal 8.x and PHP 7.x).
Now I want to load/test my existing sites in this environment but I have no idea how to achieve this.
The compose file is running fine. I have a drupal installation + MariaDB.
This is my docker-compose.yml:
version: '3'
services:
drupal:
image: jonasvbogaert/digipolis-migration:latest
container_name: drupalenv
ports:
- 8080:80
volumes:
- ./Desktop:/var/www/html/modules
- ./Desktop:/var/www/html/profiles
- ./Desktop:/var/www/html/themes
- ./Desktop:/var/www/html/sites
restart: always
environment:
DRUPAL_SITE_NAME: Drupal
DRUPAL_USER: admin
DRUPAL_PASS: admin
mariadb:
image: mariadb:latest
container_name: mariadbenv
restart: always
ports:
- 3036:3036
depends_on:
- drupal
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
UPDATE 08/25:
I think I made a little progression on this, but now I encountered a new problem.
I'm able to load the root of my website inside my docker container, but I'm not able to access it on localhost. Got a 403 error.
My folder with the docker-compose file has to be placed in the root directory of my websites.
Edited docker-compose.yml
version: '3'
services:
drupal:
image: jonasvbogaert/php-docker:${IMAGE_VERSION}
container_name: drupalenv
ports:
- 8080:80
volumes:
- ../:/var/www/html/
restart: always
environment:
DRUPAL_SITE_NAME: Drupal
DRUPAL_USER: admin
DRUPAL_PASS: admin
mariadb:
image: mariadb:latest
container_name: mariadbenv
restart: always
ports:
- 3036:3036
depends_on:
- drupal
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
One way could be as follow
as you have a fresh install of drupal you can use features module (https://www.drupal.org/project/features) to export your work/dependencies from your existing site. Then import feature into your current fresh intall of drupal