Skip to content

Instantly share code, notes, and snippets.

@jeckel jeckel/README.md
Created Sep 5, 2018

Embed
What would you like to do?
Migrate running Wordpress into Docker Swarm container

docker-compose.yml:

version: "3.2"
volumes:
  html:

services:
  wordpress:
    image: wordpress:latest
    networks:
      - traefik    
    environment:
      WORDPRESS_DB_HOST: ${MYSQL_HOST}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_NAME: ${MYSQL_DB}
      WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password
    volumes:
      - html:/var/www/html
    secrets:
      - source: mysql-db-pwd
        target: db_password
        mode: 0400
    deploy:
      labels:
        traefik.port: "80"
        traefik.frontend.rule: "Host:${WORDPRESS_HOSTNAME}"
        traefik.enable: "true"
        traefik.frontend.redirect.entryPoint: "https"
        traefik.frontend.entryPoints: "http,https"

networks:
  traefik:
    external:
      name: traefik

secrets:
   mysql-db-pwd:
    external: true

Start service, it will update the /var/www/html directory with a clean wordpress instance

Override database with your current backup.

Update database with this queries :

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-url.fr', 'http://www.new-url.fr') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-url.fr', 'http://www.new-url.fr');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-url.fr', 'http://www.new-url.fr');

# This one can fix some specific plugins option, but use it with caution...
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-url.fr', 'http://www.new-url.fr');

Load your backuped files

docker cp wp-content $CONTAINER_NAME:/var/www/html/wp-content
docker exec $CONTAINER_NAME chown -R www-data:www-data /var/www/html/wp-content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.