Ultimate docker on OSX collection - mapping docker files to local

Yes, you’ve heard, and have looked around here, here, or maybe here, it’s different to Linux with a simple volume mapped to your local machine. In OSX world, Docker is working in a VirtualBox…

So the file permission got be a problem, you can’t simply change its group or permission, neither. let’s fix it.

The idea is like this:

  • Everything in Docker operate as normal.
  • Create a new docker container that serves a ssh endpoint.
  • Connect to that ssh point, and get access to the file system inside our docker.
  • Get deeper, map the files of docker volume to local file system.

Let’s get started.

Run your containers as normal.

Go to your docker-compose directory, edit the file docker-compose.yml.

image: 'krlmlr/debian-ssh'
- '2222:22'
- SSH_KEY=ssh-rsa AAAAxxxx_ssh_rsa_pub_content rankun203@gmail.com
- data
working_dir: /var/www/html

Run it

docker-compose up sshd

Mount the docker file system to your local file system:

sshfs -p 2222 root@youdar.dev:/var/www/html ~/docker/nhweb -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=nhweb


  • volname=nhweb is the directory name of the mount point.
  • ~/docker/nhweb is the mount point.
  • These options are selected for more friendly and less errors.

Now your local folder ~/docker/nhweb are just the same as inside the Docker, but with the right access rights.


  • All the file created by you will on the name of root user inside the docker.
  • If you want to use another limited user with sudo permission, use docker.


Docker with wordpress

UPDATE (2018-05-11):

Our team at LodeStream has built a scaffold specifically for Wordpress development. You can check it out today and start play with it. Out of the box, it supports:

  • Docker, Docker Compose
  • Let’s encrypt HTTPS
  • Nginx as a reverse proxy with auto generated config
  • Simplified domain configuration
  • More information in the repo

Github repo: lodestreams/wordpress-docker-compose

The original post:

Install Docker on a Ubuntu:

Docker installation guide: https://docs.docker.com/engine/installation/linux/ubuntulinux/

If you don’t know about datastore yet, refer to: https://getcarina.com/docs/best-practices/docker-best-practices-data-stateful-applications/

  • sudo docker create -v "$PWD":/var/lib/mysql --name dbstore mysql
  • sudo docker create -v "$PWD":/var/www/html --name htmlstore php
  • sudo docker run --name mysql -e MYSQL_ROOT_PASSWORD=password --volumes-from=dbstore -dp 3306:3306 mysql
  • git clone https://github.com/youdarnet/wordpress.git
  • sudo docker run -d --name wordpress --link mysql:mysql --volumes-from=htmlstore -p 80:80 youdar/wordpress
  • sudo docker run -d --link mysql:mysql -e MYSQL_USERNAME=root --name phpmyadmin -p 3307:80 corbinu/docker-phpmyadmin


添加新的 Wordpress 网站:

使用现有的 MySQL 数据库。

  • sudo docker create -v "$PWD":/var/www/html --name wordpressNameStore php
  • sudo docker run -d --name wordpressName --link mysql:mysql --volumes-from=htmlstore -p 800x:80 youdar/wordpress


  • Remove dangling volumes: sudo docker volume ls -f dangling=true | awk 'FNR > 1 {print $2}' | xargs sudo docker volume rm
  • Run a nginx at current dir: sudo docker run -it --rm -v "$PWD":/usr/share/nginx/html -p 8081:80 nginx

  • sudo docker inspect --format="" nginx | json_pp

Read More