Docker Commands and Dockerfile

Source: Internet
Author: User
Tags docker run

Docker Commands and Dockerfile

    • Docker Commands and Dockerfile
      • Docker commands
      • Dockerfile

This paper focuses on the relevant knowledge of Docker commands and Dockerfile.

Docker commands

Website Portal:

  • Docker Run Reference
  • Docker commands

First of all, of course, the configuration command auto-completion, only need to send a file with curl to download the copy to a specific path, the specific operation reference command-line completion

In fact, Docker has a very complete command help hint, to which instruction is not clear, only need to add in the back --help to see the help description. For example:

    • docker --helpthe input can see all the executable commands.
    • Pick one, such as the run command, then input docker run --help and can see run the relevant help.

Common commands:

    • View local Images:
docker images
    • Run image
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]//i.e.imageimage /bin/bash

Some common parameters are:

    • --rm: Container automatically deleted after exiting
    • -iAnd -t often used together -it : Open a command-line window with Super Administrator privileges
    • -d: Running container in the background
    • --name: Give Container a name

    • View Current Container

-a
    • Delete all States of container
-a-q)
    • Viewing a container that is already running with another TTY
exec${container_id} /bin/bash
    • To view information about a container
${container_id}

In addition, in the above instruction, the container name and the container's container_id can be used, if the user does not specify the container name, Docker will default to each container to assign a relatively friendly random name, such as Fervent_perlman,high_galileo and so on

Dockerfile

Website Portal:

  • Dockerfile Reference
  • Best Practices for writing Dockerfiles

It feels like it's all in the document, and here's a few easy points to be confused about.

1.exec form vs Shell Form

In CMD and ENTRYPOINT both involve two forms ( CMD more of the form of a complete parameter), such as:

    • CMD ["executable","param1","param2"](exec form, recommended)
    • CMD command param1 param2(Shell form)

As for the difference between the two forms, the official notes are quite detailed, mainly the variable substitution, scripting environment and other aspects of the difference:

  • Note:if cmd is used to provide default arguments for the entrypoint instruction, both the cmd and entrypoint instructions Should is specified with the JSON array format.
  • Note:the exec form is parsed as a JSON array, which means, the must use Double-quotes (") around words not single-quo TES (').
  • Note:unlike the shell form, the exec form does not invoke a command shell. This means the normal shell processing does not happen. For example, CMD ["echo", " H OM E "]WILLNoTd ovaRIabLesubsTITuTIoNoN HOME. If you want shell processing then either use the shell form or execute a shell directly, for example:cmd ["sh", "-C", "E Cho $HOME "].

2.ENTRYPOINT vs CMD

After reading the official understand how CMD and entrypoint interact
, think that the two are very similar, what is the difference between the two and some confusion, read the following article:

Dockerfile:entrypoint vs CMD

In short, entrypoint is more like an executable command that writes dead, and Cmd is more like a default option.

An image can only be used for a single purpose, just like an executable command, it is recommended to use entrypoint and cmd as the default parameter (the third form CMD ["param1","param2"] (as default parameters to ENTRYPOINT) ). Because entrypoint is generally not overwritten (unless you explicitly use –entrypoit at run), and CMD is the defaults option, the Run command format from the previous text docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Users can override the default cmd by entering their command when running images.

3.ADD vs COPY

These two seem to be copying things from host to Docker's container, the official comparison is as follows:

Although ADD and copy are functionally similar, generally speaking, COPY is preferred. That ' s because it's more transparent than ADD. COPY only supports the basic copying of the local files to the container, while ADD have some features (like Local-only tar E Xtraction and remote URL support) that is not immediately obvious. Consequently, the best to add is the local tar file auto-extraction to the image, as in Add ROOTFS.TAR.XZ/.

In simple terms, the main difference is two points:

    • Copy can only copy local files to container, and add also supports remote copy (remotely URL support)
    • Add to automatically unzip local compressed files

Official recommendation with copy (preferred)

Reference links

Reference-add or COPY
Stackoverflow-docker COPY vs ADD

Author @brianway More articles: personal website | CSDN | Oschina

Docker Commands and Dockerfile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.