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

Methods and techniques for quickly displaying web page images

1. Use .gifs rather than .jpgs. GIFs are smaller ...

How to perfectly implement the grid layout with intervals on the page

Typical layout examples As shown in the above pic...

Analysis of the use of Linux vulnerability scanning tool lynis

Preface: Lynis is a security audit and hardening ...

Detailed explanation of how to adjust Linux command history

The bash history command in Linux system helps to...

Analysis of JavaScript's event loop mechanism

Table of contents Preface: 1. Reasons for the eve...

WeChat applet realizes multi-line text scrolling effect

This article example shares the specific code for...

Cross-origin image resource permissions (CORS enabled image)

The HTML specification document introduces the cr...

In-depth analysis of JDBC and MySQL temporary tablespace

background Temporary tablespaces are used to mana...

JavaScript design pattern learning adapter pattern

Table of contents Overview Code Implementation Su...

Summary of new usage examples of computed in Vue3

The use of computed in vue3. Since vue3 is compat...

How to load Flash in HTML (2 implementation methods)

First method : CSS code: Copy code The code is as ...