4

I'm trying to run Docker on my VPS, to maximise the use of my server.

My server mainly run LAMP stack, but I wanted to have other Docker-image based apps too.

So, I did make a Docker Container with LAMP running. The question is, how do I manage to upload files into the container (which Apache's /var/www/ is there.)?

SFTP is what I've been always using, but I can't find the way to SSH into the Docker Container, so I can access filesystem in the container, so I'd prefer that.

But if there are better practice, I'm willing to adapt it!

srakrn
  • 143
  • 1
  • 1
  • 5

1 Answers1

2

Use docker volumes, to store files in host system. For example, you can run your image with these options:

docker run --name mylamp -v /docker/site:/var/www -p 80:80 me/mylamp:tag

Now, your mylamp image mounts internal /var/www directory to external /docker/site directory, so you can use SSH/SFTP/FTP to upload files to /docker/site directory on your host system, and it will be visible inside docker image in /var/www directory.

Slezhuk
  • 375
  • 1
  • 2
  • 6
  • Thank you. Could you advice me on the permission of the file? Suppose Docker wrote the file into this directory, which account and group will be the owner of the file? – srakrn Jul 07 '16 at 07:01
  • If process from docker write file in directory, mounted as volume, in host os you will see owner and group with same uid as user inside docker container. Even if you don't have user with this uid in host system. For example, `www-data` user inside docker image have uid=33. If it write file in `/var/www` directory, on host system you will see file owner as uid=33. If you have user with same uid, but different name- you will see that user as owner, instead of www-data. So, you should check what uid have your process inside image, and use same uid as owner of directory on host system – Slezhuk Jul 07 '16 at 09:54