docker cp copy files and enter the container

docker cp copy files and enter the container

Enter the running container

# Enter the container and open a new terminal# docker exec -it container id /bin/bash
docker exec -it eaac94ef6926 /bin/bash

# Enter the original terminal of the container# docker attach container id
docker attach eaac94ef6926

Container file copy

# Copy files from the container to the Linux host# docker cp container id: path in container target host path docker cp eaac94ef6926:/home/test.txt /root/test.txt

# Copy files from the host to the container# docker cp file path container id: path in container docker cp test.txt eaac94ef6926:/home/test.txt

Official documentation: https://docs.docker.com/engine/reference/commandline/exec/

Supplement: docker cp: copy files from the container to the local

Example: Copy a test.db file from the container to the local data directory.

# Assume there is an image named kitty with a tag of 0.1, and create a container named koko# 1. create a container first
docker run -itd --name koko kitty:0.1 /bin/bash
# 2. copy test.db from koko tmp directory to local data directory.
docker cp koko:/tmp/test.db ./data/test.db
# 3. rm container koko
docker rm -f koko

Docker cp can also copy files from local to container:

# Taking the above code as an example, just reverse the container path and the local path.
docker cp ./data/test.db koko:/tmp/test.db

Supplement: Docker on Mac is mounted to local files for interoperability

Docker mounts to local files

docker run -itv /Users/XXXX/Sites/docker:/www images:12121 /bin/bash

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • How to obtain a permanent free SSL certificate from Let''s Encrypt in Docker
  • Docker solution for logging in without root privileges
  • How to modify the root password of mysql in docker
  • How to change the root password in a container using Docker
  • How to obtain root permissions in a docker container
  • Docker uses root to enter the container
  • Solution to the Docker container not having permission to write to the host directory
  • How to add a certificate to docker

<<:  MySQL commonly used SQL and commands from entry to deleting database and running away

>>:  Detailed example of using js fetch asynchronous request

Recommend

Detailed explanation of nginx proxy_cache cache configuration

Preface: Due to my work, I am involved in the fie...

Use Firebug tool to debug the page on iPad

How to debug a page on iPad? When using iOS 5, you...

Use of Linux sed command

1. Function Introduction sed (Stream EDitor) is a...

CSS achieves the effect of aligning multiple elements at both ends in a box

The arrangement layout of aligning the two ends o...

Convert XHTML CSS pages to printer pages

<br />In the past, creating a printer-friend...

25 Vue Tips You Must Know

Table of contents 1. Limit props to type lists 2....

Vue implements scroll loading table

Table of contents Achieve results Rolling load kn...

How to safely shut down MySQL

When shutting down the MySQL server, various prob...

Solution for VMware Workstation Pro not running on Windows

After the National Day holiday, did any of you fi...

Linux kernel device driver system call notes

/**************************** * System call******...

How to deploy Go web applications using Docker

Table of contents Why do we need Docker? Docker d...

Solution to Apache cross-domain resource access error

In many cases, large and medium-sized websites wi...

Web Design Experience: 5 Excellent Web Design Concepts Full Analysis (Pictures)

Unlike other types of design, web design has been ...

How to handle concurrent updates of MySQL data

Will UPDATE lock? Will the SQL statement be locke...

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...