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

Microsoft SQL Cloning Database to a Different DB Name

# User defined variables $sourceSqlServer='DEV-SQL01' $sourceDatabaseName='TEST_MSCRM' $sourceSaCredential=$(get-credential) $destinationSqlServer='DEV-SQL01' $destinationDatabaseName='Test_MSCRM' $destinationSaCredential=$(get-credential) function copyDatabase{ param( $sourceSqlServer, $sourceDatabaseName,…

Script to remove files older than X days

------------- Batch file ------------------------@echo off:: set folder pathset dump_path="E:\Shared\APP01\LOGFILES\RatingWebService2\Rating Comments\Production":: set min age of files…

How To Improve WordPress Website Rendering Speed

These are the recommended plug-ins to enable caching, database cleaning, image compressing, and minify codes…