-
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:
- checked to see if you had
hello-world
image - if not it downloads it from Docker Hub
- loaded the image into the container and ran it
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
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" "-"
docker images
- lists all imagesdocker rmi {image_id}
- remove a specific imagedocker ps
- lists running containersdocker ps -a
- list all containers including ones that previously randocker inspect
- gives info on a container or image
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