I started playing today with Docker, pulled the Centos image, configured apache inside the container with php and I am able to access the website using the ip address. However, I don't know how am I supposed to access the source files of my app that is stored inside the container, using the IDE(PHPStorm). What would be the best way to do that ?
2 Answers
The best way would be to use VOLUME and mount your source codes to the container.
That way, your IDE will have access to code in the host and all the changes you make will also be reflected in the containers.

- 11,662
- 3
- 25
- 39
-
Mounting volume to the host machine will slow down things for Magento in Mac OS, any solution for that? – Duke Jun 28 '21 at 06:03
You can install an ssh server on the container and make an SFTP connection through it. But only this container will first need to be restarted (or rather, re-created) in privileged mode (which must be done with caution, it is better to read the documentation about this), and forward the ssh port:
docker run -p 2222:22 --privileged {Image ID} /usr/sbin/init
(source - https://stackoverflow.com/a/50438053 if you don't specify --privileged
and /usr/sbin/init
, then there will be an error Failed to get D-Bus connection).
If you re-deploy the container not from the command line, but from the phpstorm interface, then it will look something like this:
https://i.stack.imgur.com/JbJv0.png
After installing the ssh server on the container, you can connect to it. Just remember to run it first - systemctl restart sshd
or service sshd restart
. Here is an example of connecting from the command line if the container is deployed locally:
ssh username@localhost -p 2222
Of course, when deploying a container, you can specify not 2222 (or any other) port, but 22, and then when connecting ssh, the port will not need to be specified at all, but then you will need to keep in mind that the default port is already occupied by this container
For good, SFTP should come with SSH (at least in my case it was like that, I tried it on centos), so after installing it, you can start setting up a connection from Phpstorm:
https://i.stack.imgur.com/wLeUm.png
Well, you can use the already familiar SFTP. But again, I repeat, you need to be careful with privileged containers, because, for example, unlike ordinary ones, they can have root access to the host machine. And secondly, in docker it is customary to distribute all services to different containers within one docker-compose, and ssh is also a service. So such a solution with ssh / sftp may be considered bad form. But so far it’s really not clear what is an even more convenient way to upload files to a container

- 1