How to copy files to the docker container (practical)

Step 1: View the docker image

Command docker images lock container tomcat

[root@ecs- ~]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
hub.cloudx5.com/justep/gateway-init    1.0                 3d26e9ba2df0        2 years ago         92.1MB
hub.cloudx5.com/justep/dbrest          1.0.1               780b3ae16949        2 years ago         106MB
hub.cloudx5.com/justep/adminer         1.0                 a16d1fd76db4        2 years ago         145MB
certbot/certbot                        latest              994e18b9d74d        2 years ago         92.2MB
<none>                                 <none>              c99efc745e9b        3 years ago         92.1MB
hub.cloudx5.com/justep/database-init   1.0                 2fe4f106e3ac        3 years ago         141MB
<none>                                 <none>              886d8c169d03        3 years ago         145MB
hub.cloudx5.com/justep/kong            0.11.2              6c215f862793        3 years ago         147MB
hub.cloudx5.com/justep/minio           1.0.2               7e4ae5d3ea35        3 years ago         281MB
<none>                                 <none>              6d131f0b7034        3 years ago         104MB
hub.cloudx5.com/justep/tomcat          8                   f550faa880e8        3 years ago         111MB
hub.cloudx5.com/justep/java            8-jre               58445151ac69        3 years ago         90.4MB

Step 2: Find the container and determine the container name

Command docker ps -a or directly find the corresponding docker ps -a | grep tomcat to view the last attribute names My name here is tomcat-chuangzhidao

[root@ecs-chuangzd ~]# docker ps -a | grep tomcat
dd43969828b5        hub.cloudx5.com/tomcat:8            "/usr/local/bin/dock…"   18 hours ago        Up 14 hours                 8080/tcp                                                                                          tomcat-chuangzhidao

Step 3: Obtain the container long ID based on the container name

Command docker inspect -f '{ {.ID}}' container name

[root@ecs-chuangzd ~]# docker inspect -f '{
    
    {.ID}}' tomcat-chuangzhidao
dd43969828b5450ec6d45e070ae82ba4c31daae8a9c2533e0495892aa137d835

Step 4: Copy the file to the specified location of the container

Command docker cp file long ID: directory, here I upload from the root directory to the container root directory

[root@ecs-chuangzd ~]# docker cp /2c3e75497b243b157bb55b96ec06e145.txt dd43969828b5450ec6d45e070ae82ba4c31daae8a9c2533e0495892aa137d835:/

Step 4: Enter the container to view the operation

Command docker exec -it [ CONTAINER ID ] /bin/bash

CONTAINER ID is the first attribute name of docker ps -a here is dd43969828b5

[root@ecs-chuangzd ~]# docker exec -it dd43969828b5  /bin/bash
bash-4.4# ls
BUILDING.txt     NOTICE         RUNNING.txt  include  native-jni-lib  work
CONTRIBUTING.md  README.md      bin          lib      temp
LICENSE          RELEASE-NOTES  conf         logs     webapps
bash-4.4# cd /
bash-4.4# ls
2c3e75497b243b157bb55b96ec06e145.txt  data  etc   media  root  srv    tmp  work
Users                                 dev   home  mnt    run   store  usr
bin                                   dist  lib   proc   sbin  sys    var
bash-4.4#

Supongo que te gusta

Origin blog.csdn.net/weixin_42517271/article/details/129632749
Recomendado
Clasificación