The end result will be a development environment which will only require vagrant up
to setup a complete Docker-based environment. The components of this environment are:
http://localhost:3000
.rake db:migrate
, rails c
etc) in the Docker environment.http://www.talkingquickly.co.uk/2014/06/rails-development-environment-with-vagrant-and-docker/
Images are containers in a certain state. Say you installed ubuntu 14.04 on a virtual machine, updated the aapt-get
definitions and installed curl
, essetial-packages
and ruby-build
.
All these changes can be saved as an image, which allows you to quickly download it and add the read-write layer on top of it and start your container. Once you add the read-write layer on top of an image, this image becomes a container.
Once your container is an a state that you would wish to preserve for duplication, commit your changes and the container is saved as an image.
sudo docker
will reveal a list of options that can be used. build
is the option we're looking for in order to create an image from a Dockerfile.sudo docker build -t ouruser/sinatra:v2 .
. We've specified our docker build command and used the -t
flag to identify our new image as belonging to the user ouruser, the repository name sinatra and given it the tag v2. We've also specified the location of our Dockerfile using the .
to indicate a Dockerfile in the current directory.We will link a pythen web container to a postgres one:
sudo docker run -d --name db training/postgres
sudo docker run -d -P --name web --link db:db training/webapp python app.py
. This will link the new web container with the db container you created earlier. The --link flag takes the form --link name:alias
, where name
is the name of the container we're linking and alias
is an alias for the link name.sudo docker inspect -f "{{ .HostConfig.Links }}" web
should show you that the 2 containers are linked.For some reason I was unable to run the sudo docker inspect -f "{{ .HostConfig.Links }}" web
command and get the expected result. However, when you run a docker web container and enter the console, you'll be able to see that the 2 containers are linked as expected:
sudo docker run -t -i --rm --name web2 --link db:db training/webapp /bin/bash
cat /etc/hosts
. apt-get install -yqq inetutils-ping && ping db
. Successful ping requests to the db container should be displayed. Exit the ping command by pressing ctrl + c
env
). You should see a series of db related variables, like DB_NAME
, DB_PORT_5432_TCP_ADDR
, DB_PORT
, DB_PORT_5432_TCP
, DB_PORT_5432_TCP_PORT
, DB_PORT_5432_TCP_PROTO
.default is read-write, but read-only can be specified...
sudo docker create -v /dbdata --name dbdata training/postgres
doesn't work, as there is no create anymore in the docker options. sudo docker run -d --volumes-from dbdata --name db1 training/postgres
sudo docker run -d --volumes-from dbdata --name db2 training/postgres
sudo docker ps
In order to create backups, we'll launch a container that adds a backups
folder and creates a backup of the /dbdata
folder:
sudo docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata
sudo docker run -v /dbdata --name dbdata2 ubuntu /bin/bash
sudo docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar
https://docs.docker.com/userguide/dockervolumes/ https://medium.com/@ramangupta/why-docker-data-containers-are-good-589b3c6c749e