Spin up a WordPress Instance with Docker/Docker-Compose

Ever needed a fast way to spin up a fresh instance of WordPress to try something out or to have your personal local dev environment?

Update 2019-09-20: You want to access the htdocs Folder of your WordPress via a SMB/SAMBA/Windows share?

You have Docker & Docker-Compose installed on your machine?

Excellent – just do the following

Setup docker-compose.yml

  • Create a new directory, eg. “wp-dev-docker
  • Inside it – create a new file called “docker-compose.yml” with the following content
version: '3.7'

services:

  wp:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    volumes:
      - wp_data_volume:/var/www/html:z
    environment:
      WORDPRESS_DB_PASSWORD: yolo123
    networks:
      - default

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: yolo123
    networks:
      - default

  samba:
    image: dperson/samba
    networks:
      - default
    environment:
      GROUPID: 0
      USERID: 0
    ports:
      - 139:139
      - 445:445
    tmpfs:
      - /tmp
    restart: unless-stopped
    stdin_open: true
    tty: true
    volumes:
      - wp_data_volume:/mnt:rw
    command: '-s "wpshare;/mnt;yes;no;no;wpshare" -u "wpshare;wpshare"'
volumes:
  wp_data_volume:

networks:
  default:
  • Open your terminal inside your previously created directory and execute
> docker-compose up -d

Access via SMB/SAMBA/Windows share

While your instance is running you can also access the WordPress files inside the htdocs-folder of your container via a SMB/Samba/Windows share. Just connect to

Share: //localhost/wpshare
User: wpshare
Password: wpshare

Hint for MacOS-Users: Connecting via “Go” -” Connect to server” leads to the error “This file server is available on your computer. Access the volumes and files locally”. Mount the share via the following commands:

> mkdir wpshare
> mount_smbfs //wpshare:wpshare@localhost/wpshare wpshare/

Linux users might use this command to mount the share:

> mount -t cifs -o user=wpshare "//localhost/wpshare" wpshare/

Important: If you ever plan to use (parts of) this docker-compose.yml file in production/publicly remember to change the passwords of WORDPRESS_DB_PASSWORD, MYSQL_ROOT_PASSWORD and wpshare/wpshare!

Further usefull Docker commands:

> docker-compose logs -f   # shows log output of both wordpress+mysql containers
> docker-compose stop      # stops the containers without removing them
> docker-compose down      # stops the containers and removes them
> docker-compose images    # shows list of both containers 
> docker volume ls         # shows a list of your current volumes
> docker volume inspect abexdxdddd # shows meta info about a specific volume
> docker volume rm abexdxdddd        # removes volume with given name - CAREFULL! this is where the data of your containers is stored

Leave a Reply

Your email address will not be published. Required fields are marked *

*