Skip to content

Instantly share code, notes, and snippets.

@Humoud
Last active March 30, 2016 13:41
Show Gist options
  • Save Humoud/9460c9d87866b8d7b304 to your computer and use it in GitHub Desktop.
Save Humoud/9460c9d87866b8d7b304 to your computer and use it in GitHub Desktop.
Docker notes from this video: https://www.youtube.com/watch?v=qidknGXzvf0

Note: dm is an alias for docker-machine

List Machines

dm ls

Create Docker Machine

dm create -d virtualbox hello-world

View Machine's Env Vars

dm env hello-world

Source Mahine's Env Vars to Local Env

eval $(dm env hello-world) or $(dm env hello-world)

and now we can docker ps

This commands basically sets the current docker machine. Kinda like pointing at it. The goal of this is to issue commands to it via the docker command.

Run an Image on the Docker Machine. Run a container

docker run <image-name>

or better run image as daemon: docker run -d <image-name>

And to map ports: docker run -d -p <local-machine's-port>:<container's-port> <image-name>

Docker is a container and it manages ports. If you don't specify a port it won't map the ports.

To name the container: docker run -d -p <local-machine's-port>:<container's-port> --name <container-name> <image-name>

Name is for referencing the container. If you don't set a name docker will give you a long hash(Container ID) which makes it hard to reference the container. You can refenerence a container by either name or Container ID.

Dockerfile

From: https://docs.docker.com/engine/reference/builder/

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Executes from top to bottom. Each line is a different instruction. FROM xxx:0.0.0 taking an image and adding it as a layer then run commands on it.

Build Docker Image

Build image from dockerfile and tag it with name 'app'. And copy the current dir and all of it's contents to the virt machine.

docker build -t app .

List All Docker Images

docker images

Link a Container to Another Container

docker run -i -t -p 3000:3000 --link <db-container-name>:<same> <app-container-name> <app-command example: rails s --port 3000 --binding 0.0.0.0

-i and -t is for interactive/inspect mode.

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