Posted On April 10, 2019

How to Import Files Into a Docker Container

kimconnect 0 comments
blog.KimConnect.com >> Codes , Linux , Virtualization >> How to Import Files Into a Docker Container

1. Use SCP to copy files to the remote server while logged onto the local machine
a. Windows command: pscp.exe c:\origin\ [email protected]:/home/user1
(source of executable: Source file:
b. Linux command: scp /home/origin [email protected]:/home/user1

2. SSH onto remote machine and elevate as a member of the docker group

ssh [email protected]
sudo docker

3. Show Container IDs

[docker@ip-172-31-10-232 user1]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c65da0f wordpress "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp kimconnect

4. Find attached volume of container

[docker@ip-172-31-10-232 user1]# docker inspect -f '{{ .Mounts }}' 6c65da0f
[{volume 90f86fa4becb6ecdb4b7e39079f6ca35c1397a57a6a375eab5c37ac2f7686f68 /var/lib/docker/volumes/90f86fa4becb6ecdb4b7e39079f6ca35c1397a57a6a375eab5c37ac2f7686f68/_data /var/www/html local true }]

4. Optional: make a backup of the existing volumes

timeStamp=$(date +%Y%m%d-%H%M%S)
homeDirectory="/home/user1"
sqlVolume="/var/lib/docker/volumes/8927da595268a3ce36386d5e910b4d503e9585f11dd311a2a700d08cf66e3fb9"
apacheVolume="/var/lib/docker/volumes/90f86fa4becb6ecdb4b7e39079f6ca35c1397a57a6a375eab5c37ac2f7686f68"
tar -C $sqlVolume -czvf $homeDirectory/sqlVolume-$timeStamp.gz _data
tar -C $apacheVolume -czvf $homeDirectory/apacheVolume-$timeStamp.gz _data
chmod 777 $homeDirectory/sqlVolume-$timeStamp.gz $homeDirectory/apacheVolume-$timeStamp.gz

5. Change into the container’s volume

cd /var/lib/docker/volumes/90f86fa4becb6ecdb4b7e39079f6ca35c1397a57a6a375eab5c37ac2f7686f68/_data

6. Copy contents from user into container’s directory

mv /home/user1/piano /home/user1/pianogame.html ./

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Installing VNC on Centos 5.3

Install VNC server package upon server setup, then run in include GNOME desktop environment: #…

PowerShell: How to Call a Batch File to Run-As Administrator

Step 1: Create a Batch File and place it inside C:\scripts @echo off powercfg.exe -x…

Unix / Linux File Permissions Cheat Sheet

General Permissions Overview: Permissions (base) 1 – execute2 – write4 – read Permissions (octal) 3…
Other project: DragonCoin.com