Skip to content

Instantly share code, notes, and snippets.

@kylefdoherty
Last active March 30, 2017 03:04
Show Gist options
  • Save kylefdoherty/f5f6a5e05833da57d3effccf0bd00782 to your computer and use it in GitHub Desktop.
Save kylefdoherty/f5f6a5e05833da57d3effccf0bd00782 to your computer and use it in GitHub Desktop.
Docker Notes

Docker Notes

Images

  • templates used to create containers that have no state and never change

  • created with the docker build command

  • composed of layers of other images

  • Ex:

docker run hello-world

When you run this command the docker engine does the following:

  1. checked to see if you had hello-world image
  2. if not it downloads it from Docker Hub
  3. loaded the image into the container and ran it

Containers

Dockerfile

Docker Ports

When you run a container with the -p command Docker Mac will make the container available on local host. So for example:

docker run -it --rm -p 3000:8080 tomcat:8.0

OR

docker run -it --rm -p 3000:80 nginx

Detached Mode

Use the -d to run the container in the background (as a daemon)

Example:

docker run -d -p 3000:80 nginx

This runs nginx in the background and gives us the container ID. We can do things like:

docker logs {container_id} to see the logs for the container. The logs for the nginx would look something like this:

afari/537.36" "-"
172.17.0.1 - - [25/Mar/2017:17:04:09 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36" "-"

Basic Docker commands

  • docker images - lists all images
  • docker rmi {image_id} - remove a specific image
  • docker ps - lists running containers
  • docker ps -a - list all containers including ones that previously ran
  • docker inspect - gives info on a container or image

Docker Inspect Example:

  • docker run -d busybox:1.24 sleep 100 - this runs the docker container in detached mode (-d) and returns the container id (ex: 984382f4122acb209dd57bb675b169106f106bf982ebd53be3870ada03082817)
  • container inspect {container_id} - this returns an array with json data about the container. You can do the same thing with a docker image id. Gives you things like the container IP & MacAddress, image id, and log path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment