Step 1: Clean Up

Remove Previous Wordpress Containers

We need to stop the Wordpress project and remove the containers before we rebuild. As you will learn, Docker containers are disposable when using volumes because the data and configurations reside outside of the containers. The containers load that data so users can interact with it.

  1. Change to the Wordpress folder using cd ~/wordpress-docker

  2. Stop the project using the command docker-compose down -v

    • Using the -v flag removes the data associated with the container.

  3. Remove any stopped containers or containers that you no longer want running.

    • View stopped containers: docker ps -a

    • Remove a stopped container using the CONTAINER ID: docker rm 1234567890

    ../../_images/container-id.png
    root@vps298933:~/wordpress-docker# docker ps -a
    CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                     PORTS                          NAMES
    925b57e101a5        hello-world          "/hello"                 5 minutes ago       Exited (0) 4 minutes ago                                  pensive_sammet
    2175f0a86466        nextcloud            "/entrypoint.sh apac…"   7 days ago          Up 6 days                  0.0.0.0:20850->80/tcp          condescending_agnesi
    root@vps298933:~/wordpress-docker#
    root@vps298933:~/wordpress-docker# docker rm 925b57e101a5
    925b57e101a5
    root@vps298933:~/wordpress-docker#
    root@vps298933:~/wordpress-docker# docker ps -a
    CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                                 NAMES
    2175f0a86466        nextcloud            "/entrypoint.sh apac…"   7 days ago          Up 6 days           0.0.0.0:20850->80/tcp                 condescending_agnesi
    root@vps298933:~/wordpress-docker#
    
  4. Clean up any dangling volumes using docker volume rm $(docker volume ls -qf dangling=true)

  5. Physically remove any data stored in the volume directory or db_data using command rm -r db_data

  6. The wordpress-docker directory should contain docker-compose.yml only.

    root@vps298933:~/wordpress-docker# ls -lh
    total 4.0K
    -rw-r--r-- 1 root root 593 Mar 23 17:43 docker-compose.yml
    root@vps298933:~/wordpress-docker#