I need to build a wordpress container(preferably using dockerfile) which has the following;
Self signed SSL certificate for Apache
Custom wp-config.php
How do I do that through a dockerfile?
I am not into WordPress but it should look something like this.
I have taken the defaults from the official docker hub repo.
Dockerfile:
FROM php:7.1-apache
ADD my.crt /etc/ssl/certs/my.crt
ADD my.key /etc/ssl/private/my.key
ADD wp-config.php /path/to/your/config/wp-config.php
Make sure that the certs are located at the right position for your apache/wordpress config.
stack.yml:
version: '2.0'
services:
wordpress:
build:
context: .
dockerfile: ./Dockerfile
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
Run with:
docker-compose -f stack.yml up --build
Related
I started working with Docker for WordPress. I followed the docker documentation to get it up and running:
https://docs.docker.com/compose/wordpress/
I added volumes for the plugin & theme directory.
When ran the command docker-compose up -d the first time and went to http://localhost:8000/ i saw the installation of WordPress. When i rebooted my PC and started the services again with: docker-compose up -d or docker-compose start i got the error message: ERR_EMPTY_RESPONSE.
I tried:
Removing the containers, services and volumes
Killing the netstat port
Currently I have no idea why it isn't working anymore. I am working on macOS
This is my current docker-compose.yml
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
volumes:
- ./plugins/my-plugin:/var/www/html/wp-content/plugins/my-plugin
- ./themes/my-theme:/var/www/html/wp-content/themes/my-theme
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpres
volumes:
db_data: {}
The status of containers after running it:
Follow these steps
docker-compose down - twice
Edit the yml file and replace all instances of db_data with db_datax
Run docker-compose up -d
Alternately,
docker-compose down - twice {removes the network as well}
docker system prune --volumes
docker-compose up -d
Just starting in docker here
So I got this in my docker-compose.yml
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_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_TABLE_PREFIX: "wp_"
WORDPRESS_DEBUG: 1
wordpress-cli:
depends_on:
- db
- wordpress
image: wordpress:cli
command: wp core install --path="/var/www/html" --url=localhost --title="Local Wordpress By Docker" --admin_user=admin --admin_password=secret --admin_email=foo#bar.com
volumes:
db_data:
So I wanted to run the wp core install so that I won't have to go through the process of manually setting up my test wordpress site.
However when I run docker-compose up, this does not seem to work, I got this error on the console
What am I missing here? Anyone can help me accomplish my goal of automating the of setting up wordpress install?
Thanks in advance
Well there are a couple of problems. The first one is that those two containers (wordpress and wordpress-cli) don't share a volume. So while wordpress has a wordpress installation ready, the wordpress-cli doesn't.
So you can add volumes to both containers, and then wordpress-cli will find the wordpress installation.
Then there's a second problem: the wordpress:latest and wordpress:cli images both run with the user www-data, but the problem is that the individual www-data users have different user-id's:
$ docker run --rm wordpress:latest grep www-data /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
$ docker run --rm wordpress:cli grep www-data /etc/passwd
www-data:x:82:82:Linux User,,,:/home/www-data:/bin/false
It seems they aren't exactly compatible here. So if you use a shared volume you have to make sure they both use the same user-id. I solved this by having the wordpress:cli run with the user xfs which also has the user id 33.
The last problem is that your containers have dependencies on each other. Wordpress needs a running MySQL instance and the wordpress-cli needs also the MySQL and the Wordpress to be ready. To make sure MySQL is ready for the wordpress cli installation you either use something like "wait-for-it" or in a simple case you can just wait a couple of seconds and then try it.
I have tested all those changes and came up with the following docker-compose.yml. I have annotated all the changes I've made with "vstm":
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_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_TABLE_PREFIX: "wp_"
WORDPRESS_DEBUG: 1
# vstm: add shared volume
volumes:
- wp_data:/var/www/html
wordpress-cli:
depends_on:
- db
- wordpress
image: wordpress:cli
# vstm: This is required to run wordpress-cli with the same
# user-id as wordpress. This way there are no permission problems
# when running the cli
user: xfs
# vstm: The sleep 10 is required so that the command is run after
# mysql is initialized. Depending on your machine this might take
# longer or it can go faster.
command: >
/bin/sh -c '
sleep 10;
wp core install --path="/var/www/html" --url="http://localhost:8000" --title="Local Wordpress By Docker" --admin_user=admin --admin_password=secret --admin_email=foo#bar.com
'
# vstm: add shared volume
volumes:
- wp_data:/var/www/html
volumes:
db_data:
# vstm: add shared volume
wp_data:
It uses a docker-volume but you can also map it to a filesystem. Depends on how you plan to use your docker-compose.
This one worked for me:
wpcli:
depends_on:
- mysql
- wordpress
image: wordpress:cli
links:
- mysql:db
entrypoint: wp
command: "--info"
container_name: ${COMPOSE_PROJECT_NAME}_wpcli
volumes:
- ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
working_dir: /var/www/html
Note that in the line:
links:
- mysql:db
mysql = name of my service
db = alias name I gave it, can be anything
Then you issue run wp like so:
docker-compose run --rm wpcli WORDPRESS_COMMAND
Source: https://medium.com/#tatemz/using-wp-cli-with-docker-21b0ab9fab79
this's my first answer at Stack Overflow :">
Actually, your question inspired me, and #vstm's answer guided me a bit.
You could try my piece of code:
1.wait-for-mysql.sh
#!/bin/bash -e
HOST=$(echo $WORDPRESS_DB_HOST | cut -d: -f1)
PORT=$(echo $WORDPRESS_DB_HOST | cut -d: -f2)
CMD=$#
until mysql -h $HOST -P $PORT -D $WORDPRESS_DB_NAME -u $WORDPRESS_DB_USER -p$WORDPRESS_DB_PASSWORD -e '\q'; do
>&2 echo "Mysql is unavailable - sleeping..."
sleep 2
done
>&2 echo "Mysql is up - executing command"
exec $CMD
2.compose.yml
version: '3.9'
services:
wordpress:
image: wordpress:5.7.0-php7.4-apache
ports:
- "80:80"
volumes:
- ./wp-data/:/var/www/html/
networks:
wp-net: {}
wp-cli:
image: wordpress:cli-2.4.0-php7.4
depends_on:
- wordpress
volumes:
- ./wait-for-mysql.sh:/wait-for-mysql.sh
- ./wp-data:/var/www/html/ # shared with wordpress service
user: "33"
command: >
/wait-for-mysql.sh
wp core install
--path="/var/www/html"
--url="http://your-url-here"
--title=your-title-here
--admin_user=your-user-here
--admin_password=your-password-here
--admin_email=your-email-here}
--skip-email
networks:
wp-net: {}
networks:
wp-net: {}
For your reference:
https://docs.docker.com/compose/startup-order/
https://gitlab.com/hino-hatake/wordpress
I try to build a web stack with docker using "php, mariadb, ngnix, composer"
I try to use only container from official repositories
following my docker-compose.yml
version: '2'
services:
nginx:
image: nginx
container_name: nginx
ports:
- "8000:80"
mariadb:
image: mariadb
container_name: mariadb
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_USER : root
MYSQL_ROOT_PASSWORD: root
php:
image: php:fpm
container_name: php
ports:
- "80:80"
volumes:
- ./php/:/var/www/html/
composer:
image: composer
container_name: composer
volumes_from:
- php
working_dir: /var/www/
volumes:
- ./composer2:/app
this docker-compose work correctly, but I don't understand why composer down quickly after 'docker-compose up -d'
PS:My first goal is to use this stack for symfony2 or silex
The composer container is ended imediatelly becuase it's not intended to run as a "daemon". In case you don't provide any command, the composer, simply said, has nothing to do. Anyways, if it has "something to do", then it executes it and ends.
You can use it through interactive shell like this:
docker run --rm --interactive --tty --volume $PWD:/app composer install
More examples are in the "Using" section here: https://hub.docker.com/_/composer/
I want to set a sendmail_path in WordPress' container and use a sendmail provided by another container. In my case its MailHog.
So this is my docker-compose:
version: '2'
services:
wordpress:
image: wordpress
links:
- db:mysql
- mailhog
ports:
- 80:80
domainname: foo.com
hostname: foo
volumes:
- ./public:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: example
depends_on:
- mailhog
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
I tried executing the command: "echo 'sendmail_path = \"/usr/local/bin/mailhog sendmail\"' > /usr/local/etc/php/conf.d/mail.ini" on WordPress container but it actually prints it...
Does these two have to share the volumes?
PS. I know I can use it as a SMTP server in the APP but I want to deal with it in more automated way.
You don't have MailHog installed in the WordPress container, so the path /usr/local/bin/mailhog doesn't exist.
What you want to do is to send emails via sendmail and those emails must be caught by MailHog. To do this, you must extend the WordPress Dockerfile:
FROM wordpress
RUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && \
chmod +x /usr/local/bin/mhsendmail
RUN echo 'sendmail_path="/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 --from=no-reply#docker.dev"' > /usr/local/etc/php/conf.d/mailhog.ini
Note the --smtp-addr parameter must be in the form <mailhog_hostname>:<mailhog_port>.
Change your docker-compose.yml to build your Dockerfile.
version: '2'
services:
wordpress:
build:
context: ./
dockerfile: ./Dockerfile
links:
- db:mysql
- mailhog
ports:
- 80:80
domainname: foo.com
hostname: foo
volumes:
- ./public:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: example
depends_on:
- mailhog
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
In this example, the Dockerfile you have written must be named "Dockerfile" and must be in the current directory (where you run docker-compose). You can change the path accordingly. You can remove the 1025:1025 ports entry if you don't need to connect to it from the host.
Now the function mail() should work as intended.
I'm try to setup a docker workspace with Alpine, PHP, Apache, MySQL and Composer.
Currently I'm trying to use the following images:
PHP, Alpine and Composer: https://hub.docker.com/r/petehouston/docker-alpine-php-composer/
Wordpress: https://hub.docker.com/_/wordpress/
I created a docker-compose.yml file to manage this dependencies for me.
docker-compose.yml
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./www:/var/www/html
links:
- db
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
alpine:
image: petehouston/docker-alpine-php-composer:latest
links:
- wordpress
So my problem is I'm trying to use the composer of the alpine container to manager my Wordpress in the wordpress container but when i try to use the following command:
docker run --rm -v $(pwd):/www -w /wordpress/var/www/html composer/composer create-project roots/sage your-theme-name 8.5.0
nothing happens, and the alpine container doesn't stay up, after i run compose-docker.up he exits
You can't access to Wordpress container from Alpine container using -w /wordpress/var/www/html.
As far as I understand, image petehouston/docker-alpine-php-composer:latest provides PHP deployment environment. That means you should use this image instead of wordpress image.
Your compose file can be like
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
alpine:
image: petehouston/docker-alpine-php-composer:latest
volumes:
- ./www:/home
links:
- db
ports:
- "8000:80"
command: composer require phpunit/phpunit
restart: always
Plz give me feedback. I'm sorry because i can't comment to get more information from you. Should you still get errors, comment here. I'll recheck