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.
Environment details:
OS X with a Virtualbox guest provisioned with docker-machine
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: [8] 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
Settings
for thedocker-machine
VM - Choose the
Network
tab - Click the
Port Forwarding
button - 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
- Click
OK
- Click
OK
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
Now visit 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 likedocker-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 thedocker-compose
commands.
Iāll try to post a more comprehensive guide soon.
Huge help! Thanks for taking the time to write such a detailed explanation. (=
@jferris Iām having issues with Docker and capybara-webkit. Didnāt find much help on google. Using the headless gem as suggested here didnāt help.
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/
Any ideas?
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.