Web Development with Docker on Mac OS X

  1. Mac OS X itself.
  2. A virtual machine (VM) running Linux inside VirtualBox, which you will start via docker-machine.
  3. Another Linux instance inside the Docker container, which is inside the VM.
$ docker-machine start default
Starting “default”…
(default) Check network to re-create if needed…
(default) Waiting for an IP…
Machine “default” was started.
Waiting for SSH to be available…
Detecting the provisioner…
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
$ eval "$(docker-machine env default)"$ docker-machine ssh default 'df -h'
Filesystem Size Used Available Use% Mounted on
tmpfs 1.8G 129.4M 1.6G 7% /
tmpfs 1001.3M 500.0K 1000.8M 0% /dev/shm
/dev/sda1 18.2G 1.9G 15.3G 11% /mnt/sda1
cgroup 1001.3M 0 1001.3M 0% /sys/fs/cgroup
Users 464.8G 318.8G 146.0G 69% /Users
/dev/sda1 18.2G 1.9G 15.3G 11% /mnt/sda1/var/lib/docker/aufs
# /Users is mounted from OS X, inside the VM

$ docker-machine ssh default 'ls -l / | grep Users'
drwxr-xr-x 1 docker staff 340 Oct 25 17:05 Users
# the /Users mount is owned by "docker"
$ docker-machine ssh default 'id docker'
uid=1000(docker) gid=50(staff) groups=50(staff),100(docker)
# user "docker" has a uid number of 1000
# Update app uid to match docker user uid
RUN /usr/sbin/usermod -u 1000 app
ADD entrypoint.sh /sbin/entrypoint.sh
RUN chmod 755 /sbin/entrypoint.sh
ENTRYPOINT ["/sbin/entrypoint.sh"]

Volumes

web:
build: .
ports:
- '80:3000'
- '80:80'
volumes:
- /Users/brent/source/my_app:/home/app/my_app
links:
- postgres
postgres:
image: postgres:latest
ports:
- '5432:5432'
$ docker-compose build
$ docker-compose up

Data Containers

$ docker run -v /var/lib/postgresql --name pgdata-dev postgres \
echo "Data-only container for postgres"
$ docker run -v /var/lib/gems --name rubygems “phusion/passenger-ruby22:0.9.18” echo “Data-only container for ruby gems”
web:
build:
.
command: /sbin/entrypoint.sh
ports:
-
'80:3000'
- '3000:3000'
volumes:
-
/Users/brent/source/my_app:/home/app/my_app
volumes_from:
-
rubygems
links:
-
postgres
postgres:
image:
postgres:latest
volumes_from:
-
pgdata-dev
ports:
-
'5432:5432'
echo
echo "Installing Bundler..."
gem install bundler
echo
echo "Changing /var/lib/gems permissions to the app user..."
chown -R app:app /var/lib/gems
echo
echo "Running bundle install (as app user)..."
su - app -c "GEM_HOME=/var/lib/gems /home/app/workshops/bin/bundle install"

--

--

--

Systems integrator, software developer, future gazer.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brent Kearney

Brent Kearney

Systems integrator, software developer, future gazer.

More from Medium

CodeIgniter 4 Query Builder set() function with update()

A caveat: CORS in JAX-RS REST APIs

How to Manage and Use Apache virtual hosts in Ubuntu

Setup Git on WP Engine