


What is the difference between copy and add instructions in docker
Difference: The COPY instruction does not support obtaining resources from remote URLs. It can only read resources from the host where docker build is executed and copy them to the image; while the ADD instruction supports obtaining resources from remote URLs, which can be obtained through the URL. Read resources from the remote server and copy them to the image.
The operating environment of this tutorial: linux5.9.8 system, docker-1.13.1 version, Dell G3 computer.
Both the COPY instruction and the ADD instruction in the Dockerfile can copy or add resources on the host to the container image, both of which are completed during the process of building the image.
The difference between ADD and COPY of DockerFile
The only difference between the COPY instruction and the ADD instruction is: whether it supports obtaining from a remote URL resource.
The COPY instruction can only read resources from the host where docker build is executed and copy them to the image. The ADD instruction also supports reading resources from the remote server through the URL and copying them to the image.
For the same requirements, it is recommended to use the COPY instruction. The ADD instruction is better at reading local tar files and decompressing them.
ADD and COPY instructions
COPY has the same syntax as ADD and copies files.
ADD
Copy the new file, directory, or remote file URL
Each
Add all files starting with "hom":
ADD hom* /mydir/
In the example below, ? is replaced with any single character, such as "home.txt".
ADD hom?.txt /mydir/
ADD instruction has the following advantages:
1. If the source path is a file and the target path ends with /, then docker The target path will be treated as a directory and the source files will be copied to the directory.
If the target path does not exist, the target path will be automatically created.2. If the source path is a file and the target path does not end with /, docker will treat the target path as a file.
If the target path does not exist, a file will be created with the name of the target path, and the content will be from the same source file;
If the target file is an existing file, it will be overwritten with the source file. Of course, only the content will be overwritten, and the file name will be the same. Target file name.
If the target file is actually an existing directory, the source file will be copied to the directory. Note that in this case it is best to end the display with / to avoid confusion.3. If the source path is a directory and the target path does not exist, docker will automatically create a directory with the target path and copy the files in the source path directory.
If the target path is an existing directory, docker will copy the files in the source path directory to the directory.4. If the source file is an archive file (compressed file), docker will automatically decompress it.
The above advantages are also the disadvantages of ADD
Recommended learning: "docker video tutorial"
The above is the detailed content of What is the difference between copy and add instructions in docker. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

To get the Docker version, you can perform the following steps: Run the Docker command "docker --version" to view the client and server versions. For Mac or Windows, you can also view version information through the Version tab of the Docker Desktop GUI or the About Docker Desktop menu.

To save the image in Docker, you can use the docker commit command to create a new image, containing the current state of the specified container, syntax: docker commit [Options] Container ID Image name. To save the image to the repository, you can use the docker push command, syntax: docker push image name [: tag]. To import saved images, you can use the docker pull command, syntax: docker pull image name [: tag].

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".
