Dockerfiles Commands (James Lee)

        1. RUN - commands you want ran to BUILD IMAGE
          1. Any linux command. Same syntax as if from terminal
          2. Each RUN command builds a unique layer in the image
          3. Suggest chaining Run commands so fewer layers

Put in alphanumerical order so easy to find

Chaining also ensures all updates are checked

Otherwise cache is used for all but “new” commands” (when chained, entire command is modified so all pkgs (git, python, etc) updated

Example (reduces 3 RUN from above to 1 RUN)

RUN apt-get update && apt-get install -y \

git \

python \

Vim

        1. CMD - instructions ran when CONTAINER is built
          1. If no COMMANDs given in Dockerfile, Docker uses default command defined in the base image
          2. COMMAND can be given in “execute form” (preferred) or shell
          3. Users can override the default CMD by specifying an argument after the image name when starting the container
          4. COMMAND [“/bin/bash”]

to open shell when container is run (& user tags -it)

        1. COPY - copies folder or files from build context & adds to file system of container
          1. COPY <path_to_file_from_Dockerfile> <path_in_Container>
          2. COPY temp.txt src/temp.txt
          3. NOT live-linked. Once image is made, files copied over are set. If change source code, must rebuild image to see changes. Use “volume” when build container to live-link code (see below)
        2. ADD - similar to COPY but can also download source files from internet
        3. USER - user whose access rights used to run image’s resultant container
          1. Best practice - set to “unpriviledged” user (w/o admin rights) b/c of fear container breached and user gains access to host (OsX). Example USER sierrawells or USER admin
        4. WORKDIR - directory from which Dockerfile commands run
          1. CMD, RUN COPY ADD ENTRYPOINT

results matching ""

    No results matching ""