Two ways to create an image

Commit changes made to a container (but not pushed yet to dockerhub.com)

        1. Example: Create Debian Linux base with git installed
        2. $ docker run -it debian:jessie (-it = interactive so get terminal)
        3. /# apt-get update && apt-get install -y git (apt-get is package installer like npm)
        4. Commit changes to your DockerHub account
          1. $ docker commit <cont_ID> <user_Name>/<image_Name>
          2. $ docker commit [OPTIONS] <cont_ID> [REPOSITORY/img_name:TAG

-m, --message string Commit message

From a Dockerfile

FROM debian:jessie

RUN apt-get update

RUN apt-get install -y git

RUN apt-get install -y vim

Build image from Dockerfile

      1. $ docker build -t <image_name> <Dockerfile relative location . = cwd>

$ docker build -t dougwells/debian . → . = cwd (works if Dockerfile is in cwd)

$ docker build -t dougwells/debian Dropbox/1-Code/Docker/DockerBasics2

        1. Since image built with Dockerfile, no version #. Instead tagged w/”latest”
          1. Docker images → dougwells/debian:latest
        2. Avoid temptation to use :latest. Rather, give version #
      • Rename image, use $ docker tag

$ docker tag <image_id> <new_image_name>:tag

        1. Remember, try to avoid leaving off tag (defaults to “latest”)
        2. But, if building new image with this image as a layer, if your existing layer in cache already has “latest”, it won’t update b/c docker thinks you have the latest (which you might or might not)

Image Naming cautions:

      1. Build manually (ie, $ docker build -t dougwells/debian .)
        1. Image name = Image name given
        2. Example node or dougwells/node
      2. Build image locally with docker-compose.yml
        1. Image name = <folder of docker-compose.yml>_<service name given in docker-compose-yml>
      3. Build image in CircleCI - (built from github repo)
        1. Image name = <gh repo name (with dashes [-]removed) >_<service name given in docker-compose.yml

Pushing image to DockerHub.com (James Lee)

        1. Make sure image has format <DockerHub_Username>/<image_Name>
          1. If not, rename it using “docker tag” (‘tagged” w/ a name)
          2. $ docker tag <current_img_id> <new_img_name>:tag
        2. Login to Docker Hub from CLI
          1. $ docker login --username=dougwells -- or --
          2. docker login
        3. Then push to Docker Hub
          1. $ docker push <repository_name>/<image_name>:tag
          2. Example: $ docker push dougwells/debian:1.01

Publishing images to Docker Hub (Dan Wahlin)

      1. $ docker login → must be logged in first
      2. $ docker push <your username>/<image-name>
        1. Must use this format <username>/<image-name> or will not push
        2. If need to rename image to follow naming convention
          1. docker tag <image_id> <new_image_name>:tag

Remember, try to avoid leaving off tag (defaults to “latest”)

But, if building new image with this image as a layer, if your existing layer in cache already has “latest”, it won’t update b/c docker thinks you have the latest (which you might or might not)

      1. $ docker pull <filename>
      2. $ docker run <filename> → (docker will download image if not on machine yet)

results matching ""

    No results matching ""