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

PowerShell: List Currently Logon Users On Remote Servers

# Show current sessions on a list of servers$servers="SHERVER005","SHERVER007";$servers|%{"$_`n$(query user /server:$_|Out-String)"} # Sample OutputPS C:\Windows\system32>…

Kubernetes: Use Helm to Deploy WordPress

Deploying WordPress in a Kubernetes cluster isn't as straight-forward is one might expect. As the…

Indications that Chocolatey is locked down

# System's version is less than vendor's current (Chocolatey v0.10.15) 0+000+00[LAX-WEB005]: PS C:\Users\testadmin\Documents> choco source…