This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/intro-to-docker
Thanks, that was great explanation of some Docker concepts I’ve found tricky to understand. It’s encouraged me to try containerize one of own apps.
Certainly the biggest caveat in dev is performance.
It is perfectly fine when used on Linux.
But on a mac since it runs through boot2docker (a small vm) and since you have to share your projet repo with boot2docker and then boot2docker shares them with docker containers… It slows everything down
It works with small projects but when you begin to have a lot of assets it becomes really really slow.
Make sure to share your directories with boot2docker through nfs.
An even better solution is to create a custom vm with vagrant. Install docker on this vm and sync your directories with rsync (rsync is available as an option with vagrant and shared directories).
Thanks Chris, Joe, and Thom. This motivated me to noodle around a bit with docker. I did run into an issue with one of the commands from the show notes. I figured I’d add some documentation here about my experience for anyone else following along and having trouble on OS X.
OS X with a Virtualbox guest provisioned with
VirtualBox 5.0.4-102546 => docker-machine --version docker-machine version 0.4.1 (HEAD) => docker --version Docker version 1.8.2, build 0a8c2e3
Starting the upcase rails server with the following command fails:
docker run --link=db -it upcase -p 3000 bin/rails server -b 0.0.0.0
Error response from daemon: Cannot start container e82e64ed06bb1dc476d5f0a2b6156afd56d458a96fb95daf6be23411649de663:  System error: exec: "-p": executable file not found in $PATH
This indicates that the container is trying to run the port option as a command within the container. Ok no problem, just move the
-p 3000 option before the
-it upcase option.
Now the container starts, but requests to
localhost:3000 fail with the following error:
Failed to load resource: Could not connect to the server.
This indicates that the host OS can’t connect to the Virtualbox Docker VM running our container. So forward the VM ports through to the host.
- Open Virtualbox
- Open the
- Choose the
- Click the
- Add a rule with the following values:
- Name: Webrick
- Protocol: TCP
- Host IP: 127.0.0.1
- Host Port: 3000
- Guest IP: (intentionally blank)
- Guest Port: 3000
Now when we navigate to
localhost:3000 from the host OS we’re faced with the following error:
Failed to load resource: The network connection was lost.
Simple enough, now we need the docker container to setup the host-guest port forwarding. So stop the upcase docker container and start it again with the following command – notice the changes to the
-p 3000:3000 parameter:
=> docker run --link=db -p 3000:3000 -it upcase bin/rails server -b 0.0.0.0
localhost:3000 and you should see a response from the rails process running inside the upcase container.
Hope this helps someone else who’s having a hard go of it on OS X.
Any suggestions on using docker in development and still being able to do BDD / TDD. I like being able to run specs from my editor, and I like that spring has made running specs and getting feedback super fast, but I am not sure how to achieve that using docker.
I’ve been doing TDD with Docker. I’m pretty swamped today, so I can’t give a cohesive answer, but here are some tips:
- You can override the command for a service using
docker-compose run, so you can run commands like
docker-compose run web rspec <file>.
- If you’re using vim-rspec, you can override the command to include
docker-compose run. You can also create new binstubs which include the
I’ll try to post a more comprehensive guide soon.
Huge help! Thanks for taking the time to write such a detailed explanation. (=
The error I’m getting is:
Capybara::Webkit::ConnectionError: /usr/local/bundle/gems/capybara-webkit-1.6.0/bin/webkit_server failed to start.
My Dockerfile looks like:
FROM ruby:2.3.0 RUN apt-get update -qq \ && apt-get install -y --no-install-recommends \ dbus-1-dbg \ libpq-dev \ libqt5webkit5-dev \ libqtwebkit-dev \ nodejs \ qt5-default \ xvfb RUN mkdir /app WORKDIR /app COPY Gemfile /app/ COPY Gemfile.lock /app/ RUN bundle install COPY . /app/
Have you tried using
xvfb-run? I’ve had good luck with that. Looks like you already have xvfb installed, so you can do
xvfb-run -a rake, for example. Check out the man page for more info.
If you run
webkit_server directly, it may provide more information about what went wrong. You can use something like:
docker-compose run web /usr/local/bundle/gems/capybara-webkit-1.6.0/bin/webkit_server.
Out of interest, does anyone using Rails with Docker also have a private gem server they need to install Gems from? If so how do you manage that in your Dockerfile? By default bundler stores the credentials for a private repo in
~/.bundler/config on the host machine. A Docker build cannot see that file by design, so I can’t copy it into a Docker image so that private gems will be resolved.