question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Environment of Python Task is different from that of real worker container

See original GitHub issue

My DS system is setup by Docker. When I ran like this in a PythonTask, I found that env is different from what i got in the docker container of worker. image This is what env showed by the Python Task. image And this is what env showed by execute os.system("env") or os.environ directly in the container of worker. image

I don’t know why they are totally different, especially the Variable ‘PATH’. I thought that docker container is exactly where python executes script. So i am confused

Which version of DolphinScheduler: -[1.3.6-release]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chengshiwencommented, Jun 23, 2021

@wangdazhong001 Under different user, the result of env is different. Regardless of whether it is in the docker container, the same thing happens in linux on the host machine. The richer environment variables directly in the container of worker occur under roor user. While the environment variables from the python task occur under the user whose id is 2.

Since the python script does not execute source /opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh, the python task cannot read the environment variables in this file.

If you want to access the environment variables from /opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh, there are four solutions:

  1. open('/opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh', 'r') and parse it
  2. Use python-dotenv
  3. Use the following code:
import os
import pprint
import shlex
import subprocess

command = shlex.split("env -i bash -c 'source /opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh && env'")
proc = subprocess.Popen(command, stdout = subprocess.PIPE)
for line in proc.stdout:
  (key, _, value) = line.partition("=")
  os.environ[key] = value
proc.communicate()

pprint.pprint(dict(os.environ))
  1. Use shell task instead of python task
source /opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh
python /path/to/your_python_script.py
0reactions
chengshiwencommented, Jul 2, 2021

Close since it has been replied

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem running celery in a different docker container than the ...
I've found that It works only if I add this to the docker-compose definition of the celery service: environment: - C_FORCE_ROOT=true.
Read more >
Best practices for containerizing Python applications with Docker
In this post, we'll attend to those concerns and take a look at some 6 best practices when containerizing Python applications with Docker....
Read more >
Task Queue Overview - App Engine - Google Cloud
Task queues come in two flavors, push and pull. The manner in which the Task Queue service dispatches task requests to worker services...
Read more >
Top 50 Kubernetes Interview Questions and Answer for 2023
How is Kubernetes different from Docker Swarm? What is Kubernetes? How is Kubernetes related to Docker? What is the difference between deploying ...
Read more >
Environment Dependencies — Ray 2.1.0
Your Ray script may import/depend on some Python packages. ... You can specify different runtime environments per-actor or per-task using .options() or the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found