Skip to content

Instantly share code, notes, and snippets.

@soifou
Last active November 21, 2016 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soifou/b2d2fcc04318a8d11b12 to your computer and use it in GitHub Desktop.
Save soifou/b2d2fcc04318a8d11b12 to your computer and use it in GitHub Desktop.
Docker init

Docker

Installation

Debian 8 (Jessie) 64 bits

# apt-get purge lxc-docker* docker.io*
# apt-get update
# apt-get install -y apt-transport-https ca-certificates
# apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
# echo deb https://apt.dockerproject.org/repo debian-jessie main >> /etc/apt/source.list.d/docker.list
# apt-get install docker-engine
# usermod -aG docker <your_username>
# service docker start

OSX (with Homebrew)

brew cask install virtualbox
brew install docker docker-machine docker-compose
docker-machine create --driver virtualbox dev
docker-machine ls
docker-machine ssh dev

Then, export some DOCKER vars to your current shell to connect the Docker client to the Docker daemon:

eval "$(docker-machine env dev)"

Use NFS instead of VBOXFS

To speed up file sharing, consider to activate NFS for an existing boot2docker box created through Docker Machine.

$ curl -s https://raw.githubusercontent.com/adlogix/docker-machine-nfs/master/docker-machine-nfs.sh |
  sudo tee /usr/local/bin/docker-machine-nfs > /dev/null && \
  sudo chmod +x /usr/local/bin/docker-machine-nfs

Then

$ docker-machine-nfs dev

See : https://github.com/adlogix/docker-machine-nfs

Entry points

By default, the folder /Users is shared from your host to your docker machine. To communicate with your containers, you should store your files into /var/lib/boot2docker. It is the only persisted folder during reboot.

Configuration

If you want to move docker images to a different partition, edit /etc/default/docker file with the -g option:

DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"

Reboot docker. Now docker has enough space.

DNS issue (OSX Yosemite ?)

If you have networking issue inside docker containers (when you build an image or use a container to grab some packages over internet) that usually work in local env, ie. php_network_getaddresses: getaddrinfo failed or something related to your technology, it's probably a DNS issue, there is a nice workaround:

$ docker-machine stop dev-nfs
$ VBoxManage modifyvm dev-nfs --natdnsproxy1 off --natdnshostresolver1 off
$ docker-machine start dev-nfs

See: boot2docker/boot2docker#451 (comment)

Command examples

  • Start a LAMP container
docker search lamp
docker pull tutum/lamp
docker run -d -p 80:80 -p 3306:3306 tutum/lamp
  • Manage containers
$ docker ps
$ docker start <container-id|name>
$ docker stop <container-id|name>
  • Remove all your containers/images:
$ docker rm $(docker ps -a -q)
$ docker rmi $(docker images -q)
  • SSH connect to a specific container
$ docker exec -ti <container-id|name> bash
  • Display the memory and CPU use of all your containers
$ docker stats $(docker ps -q)
  • Help
$ docker
$ man docker run

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment