Thursday, August 16, 2018

Accessing Files on a Windows Docker Container Easily

Leave a Comment

Summary

So I'm trying to figure out a way to use docker to be able to spin up testing environments for customers rather easily. Basically, I've got a customized piece of software that want to install to a Windows docker container (microsoft/windowsservercore), and I need to be able to access the program folder for that software (C:\Program Files\SOFTWARE_NAME) as it has some logs, imports/exports, and other miscellaneous configuration files. The installation part was easy, and I figured that after a few hours of messing around with docker and learning how it works, but transferring files in a simple manner is proving far more difficult than I would expect. I'm well aware of the docker cp command, but I'd like something that allows for the files to be viewed in a file browser to allow testers to quickly/easily view log/configuration files from the container.

Background (what I've tried):

I've spent 20+ hours monkeying around with running an SSH server on the docker container, so I could just ssh in and move files back and forth, but I've had no luck. I've spent most of my time trying to configure OpenSSH, and I can get it installed, but there appears to be something wrong with the default configuration file provided with my installation, as I can't get it up and running unless I start it manually via command line by running sshd -d. Strangely, this runs just fine, but it isn't really a viable solution as it is running in debug mode and shuts down as soon as the connection is closed. I can provide more detail on what I've tested with this, but it seems like it might be a dead end (even though I feel like this should be extremely simple). I've followed every guide I can find (though half are specific to linux containers), and haven't gotten any of them to work, and half the posts I've found just say "why would you want to use ssh when you can just use the built in docker commands". I want to use ssh because it's simpler from an end users perspective, and I'd rather tell a tester to ssh to a particular IP than make them interact with docker via the command line.

EDIT: Using OpenSSH

Starting server using net start sshd, which reports it starting successfully, however, the service stops immediately if I haven't generated at least an RSA or DSA key using:

ssh-keygen.exe -f "C:\\Program Files\\OpenSSH-Win64/./ssh_host_rsa_key" -t rsa 

And modifying the permissions using:

icacls "C:\Program Files\OpenSSH-Win64/" /grant sshd:(OI)(CI)F /T 

and

icacls "C:\Program Files\OpenSSH-Win64/" /grant ContainerAdministrator:(OI)(CI)F /T 

Again, I'm using the default supplied sshd_config file, but I've tried just about every adjustment of those settings I can find and none of them help.

I also attempted to setup Volumes to do this, but because the installation of our software is done at compile time in docker, the folder that I want to map as a container is already populated with files, which seems to make docker fail when I try to start the container with the volume attached. This section of documentation seems to say this should be possible, but I can't get it to work. Keep getting errors when I try to start the container saying "the directory is not empty".

EDIT: Command used:

docker run -it -d -p 9999:9092 --mount source=my_volume,destination=C:/temp my_container 

Running this on a ProxMox VM.

At this point, I'm running out of ideas, and something that I feel like should be incredibly simple is taking me far too many hours to figure out. It particularly frustrates me that I see so many blog posts saying "Just use the built in docker cp command!" when that is honestly a pretty bad solution when you're going to be browsing lots of files and viewing/editing them. I really need a method that allows the files to be viewed in a file browser/notepad++.

Is there something obvious here that I'm missing? How is this so difficult? Any help is appreciated.

1 Answers

Answers 1

Try this with Docker composer. Unfortunately, I cannot test it as I'm using a Mac it's not a "supported platform" (way to go Windows). See if that works, if not try volume line like this instead - ./my_volume:C:/tmp/

Dockerfile

FROM microsoft/windowsservercore  # need to ecape \ WORKDIR C:\\tmp\\  # Add the program from host machine to container ADD ["<source>", "C:\tmp"]  # Normally used with web servers # EXPOSE 80  # Running the program CMD ["C:\tmp\program.exe", "any-parameter"] 

Docker Composer

Should ideally be in the parent folder.

   version: "3"      services:       windows:         build: ./folder-of-Dockerfile         volume:           - ./my_volume:C:/tmp/         ports:           - 9999:9092 

Folder structure

|---docker-composer.yml     |     |---folder-of-Dockerfile         |         |---Dockerfile 

Just run docker-composer up to build and start the container. Use -d for detach mode, should only use once you know its working properly.

Useful link Nanage Windows Dockerfile

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment