I am in the process of configuring a multi-container setup for Wordpress using Docker (as per this article ).
At present, I have a wordpress
service which has a named volume in it like so:
volumes:
- wordpress:/var/www/html
Which works perfectly for the default Wordpress installation. But I also have some files that I need to pass into the container for the theme/plugins etc.
I understand that this would also be achievable by setting a mapping between the two paths on the server and the relevant container. Something like this:
volumes:
- ./wp-content:/var/www/html/wp-content
It's my understanding that a volume is named so that other containers can interact with it (as is required in my case, which you can see in the full docker-compose.yaml
file below).
So, what is the correct way to create a named volume which sets the paths so my files are mounted on the container?
Here is the full docker-compose.yaml
file:
version: '3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
env_file: .env
volumes:
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=$MYSQL_DATABASE
volumes:
- wordpress:/var/www/html
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- app-network
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
env_file: .env
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
networks:
- app-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
env_file: .env
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email ${LETSENCRYPT_EMAIL} --agree-tos --no-eff-email --staging -d ${DOMAIN} -d www.${DOMAIN}
volumes:
certbot-etc:
wordpress:
dbdata:
networks:
app-network:
driver: bridge
you can copy files to your named Volume using the following:
docker cp /my/folder/myfile container:/var/www/html/myfile
replace container
with your container name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.