Skip to content

Instantly share code, notes, and snippets.

@tresorama
Last active April 10, 2024 15:22
Show Gist options
  • Save tresorama/f09b44fc5ed13dc170c926f863ee27d3 to your computer and use it in GitHub Desktop.
Save tresorama/f09b44fc5ed13dc170c926f863ee27d3 to your computer and use it in GitHub Desktop.
How to move a Local by Flywheel site to a plain Docker (docker-compose) site

How to move a Local by Flywheel site to a plain Docker (docker-compose) site

  1. Open docker deskop

  2. Create a directory for your prject crete this file structure:

    docker-compose.yml # we fill this in next step
    data
      db-data # leave blank, this will be used by mysql to persist data
      db-exports
          local.sql # copy this file from `<your Local site>/app/sql`
      wp-content # copy this folder from `<your Local site>/app/public/wp-content`
    
  3. edit data/db-exports/local.sql by adding USE demo; as first line of the file.

  4. fill the docker-compose.yml

    version: '3'
    services:
      wordpress:
        image: wordpress
        ports:
          - "3000:80"
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_NAME: demo
          WORDPRESS_DB_USER: user
          WORDPRESS_DB_PASSWORD: user
        volumes:
          - ./data/wp-content:/var/www/html/wp-content
        depends_on:
          - "db"
    
      db:
        image: mysql:8.0.16
        environment:
          MYSQL_ROOT_PASSWORD: user
          MYSQL_DATABASE: demo
          MYSQL_USER: user
          MYSQL_PASSWORD: user
        volumes:
          - ./data/db-data:/var/lib/mysql
          - ./data/db-exports:/var/lib/mysql-db-exports
    
      adminer:
        image: adminer
        ports: 
          - "3001:8080"
        depends_on:
          - db
    
  5. Run docker compose up to start containers

  6. Check that wordpress is reachable at http://localhost:3000. DO NOT USE THE INSTALL WIZARD, CLOSE THE PAGE!

  7. Restore database do this in cli:

    # ==================
    # list all runnnig container
    # ==================
    docker ps
    # CONTAINER ID   IMAGE          
    # c1d8521b20a3   wordpress 
    # 1d85947867c4   mysql:8.0.16
    
    # enter the “mysql” container shell
    docker exec -it 1d85947867c4 bash
    
    
    # ==================
    # Restore mysql dump file
    # ==================
    # 1/ restore file
    # username and password come from docker-composeyml file
    # mysql-db-experts is mapped in docker-composeyml file
    mysql —user=“user” —password=“user” < /var/lib/mysql-db-exports/local.sql
    
  8. Search and replace domain in db

    # ==================
    # list all runnnig container
    # ==================
    docker ps
    # CONTAINER ID   IMAGE          
    # c1d8521b20a3   wordpress 
    # 1d85947867c4   mysql:8.0.16
    
    # enter the “wordpress” container shell
    docker exec -it c1d8521b20a3 bash
    
    # ==================
    # searhc and replace domain
    # ==================
    wp search-replace 'https://my-site.local' 'http://localhost:3000' --allow-root
    wp search-replace 'my-site.local' 'localhost:3000' --allow-root
    
  9. See the site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment