Perl / docker-perl

Dockerfiles for index.docker.io (official Perl Docker image)

Home Page:https://registry.hub.docker.com/_/perl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Talking to docker using Synology NAS

paytah232 opened this issue · comments

Hi creators, loving this package, works great. I don't know if you have synology experience, but you will have docker experience. What I'm doing is running a perl script (from a sh file) inside a bash terminal window inside docker. I run it like "./file.sh". This works like a charm.

My next step is to automatically run this file from 'outside' the docker. I want to use synology task scheduler to run the command:
docker exec -it container_name bash ./file.sh

However, this doesn't seem to work as I can't see the bash window start and my file doesn't create an output like it's meant to. Can you help me figure out how to do this?

Is file.sh located outside the container? If so, you need to either (a) add the file into a derivative image, or (b) mount the file into the container via -v option.

If it is already inside the container, could you try docker exec -it container_name /bin/bash /path/to/file.sh (that is, specify full paths to both bash and the script.) You can also add set -ex into your script to see the command trace.

@zakame the file is inside the container. When specifying the full path, do I not need to do "./file.sh" to execute? Or is simply the full path to the file enough?

Also, when I run this command, should I be able to see a bash window open inside the docker container? I'd like this so I can track the text output my file.sh outputs to the console.

Cheers.

The full path should be enough, if it is already inside the container; it is also usually safer, since ./file.sh might refer to a different file than intended due to how WORKDIR is set.

You should see the script's output to console when you run it; placing the set -ex command right near the start of the script should give even more verbose output (and also terminate sooner if something else stops working.)

Alright thanks mate. I'll give this a go later tonight and let you know how it goes.

commented

docker exec -it container_name bash ./file.sh

Is the container running at the time you call this command?
Make sure the file is executable, then you can use

docker exec container_name /path/to/file.sh

or if you started it with compose

docker-compose exec service_name /path/to/file.sh

Yes container is already running as it autostarts when the NAS does. I will try this later tonight and report back.

Still no action from the container trying all the methods above.

I can still run 'docker stop container_name' and the container will stop, can do start as well, but I tried just doing 'docker exec container_name /bin/bash' and still nothing happened.

What should I do to try next? I really want to get this working and I am surre it is possible.

Try passing --interactive --tty to the docker run/exec, e.g. docker exec -it container_name /path/to/file.sh. Normally docker exec/run won't attach a tty or STDIN/STDOUT on a bare call.

Nope. Still getting no response from the container.

commented

@zakame He only needs -it if he wants to open the shell an type commands into it.
Two simple commands to try:

docker exec container_name ls
docker exec container_name perl --version

Works on WSL, no idea why it shouldn't work on a Synology NAS.

@Tekki What should I be seeing when I run those commands. So what I'm doing is running the docker command using the task scheduler in Synology NAS. Then I have the Process window for my container open to see if anything changes. Normally, if I open a bash terminal within the container, the process window shows a new /bin/bash process, and then when I run my file.sh, it shows that as a separate process too. But when I run 'docker exec container_name /bin/bash /path/to/file.sh', nothing at all happens. The task schedule runs the command as root too, so it should have all the right permissions set.

Update: I checked the output file from the task scheduler and I am getting an error. Can I get some help with it please:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.29/containers/Perl_for_TV_Guide/exec: dial unix /var/run/docker.sock: connect: permission denied

Further update: Nevermind I think I may have reset my container and lost the dependancies. If that's the case, I will check after they install and then close the issue. Thanks for all the help everyone.

commented

Just a second: If the task scheduler is something similar to cron then my first idea is that the environment variables are not set.

@paytah232 FWIW asking over at https://forums.docker.com/c/general-discussions might be more appropriate than here (it doesn't seem that the underlying Perl script you're running has issues, yet.)

@Tekki the -it for exec/run is worth at least for debugging; if we're not seeing any outputs there then I doubt a normal exec/run would work as well.

Hi, let me close this as there has been no activity since; feel free to update if there is (or open a new issue.)