0

Disclaimer: I have no practical knowledge of Docker. I have never worked with it before.

My company just took over a website for a client. The previous developer is out of the question and the client has no technical people. We dont (and wont) have access to any previous source control, assets, or processes. We only have SSH access to the production server.

How can I pull source code and database down from the server when its in a Docker container? Is it possible to reverse engineer the Docker container for our developers to work with?

2 Answers 2

4

The good part is this is very easy!

So you can view all running containers via

docker ps

Once you have the ID of the container you need you can run

docker exec -it DockerContainerID sh

That will drop you into a shell of the container and once you locate the code you can copy it off to the host via the following command

docker cp DockerContainerID:/path/on/container ./localdir

Then you can get it to a local spot and into source control.

To get the DB you can dump the DB inside the container and then use the docker cp command to get the backup off where you can import it somewhere else.

6
  • I regret that I only have one upvote to give. Thanks!
    – Jeff
    Oct 19, 2017 at 21:31
  • ya docker is great and its like a little VM and you can easily get stuff in/out of it.
    – Mike
    Oct 19, 2017 at 21:33
  • Probably a question for another thread but the docker shell is reporting that mysql: not found, yet the source code is point to 127.0.0.1. docker exec -it <id> mysql is also not finding mysql. How can Docker be concealing the mysql if the app is point to 127.0.0.1?
    – Jeff
    Oct 19, 2017 at 21:58
  • are you sure its mysql? might be another container and DB info is passed in via env vars.. in the app container you can run env to look
    – Mike
    Oct 19, 2017 at 22:03
  • I'm sure it is mysql (or maria) but there seems to be a discrepancy in the source code. Environment variables would imply a remote mysql server, but source code doesnt appear to use the environment variables. Thats straying a little far from the original question and the environment variables have given me enough to continue the investigation. Thanks again.
    – Jeff
    Oct 19, 2017 at 22:15
2

Answer given by Mike is very helpful. Just wanted to add some more point. You can also check if there is any volume mount point for the container. Generally container has volume mounted on host for data directories (eg./var/www/html). So you can directly copy data from host without pulling data out from container.

docker inspect container_ID | grep -i -A 10 bind
"Binds": [
        "/webdata:/var/www/html:rw"
       ],

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .