Note: dm is an alias for docker-machine
dm ls
dm create -d virtualbox hello-world
dm env hello-world
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.
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.
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 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 .
docker images
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.