Hi,
I have .sh that populates my docker setup and or works wonders. Although, I am now needing to
export the variables to a send them to another machine. Is this possible?
Thanks,
Aaron
Share and learn in the Docker community.
Hi,
I have .sh that populates my docker setup and or works wonders. Although, I am now needing to
export the variables to a send them to another machine. Is this possible?
Thanks,
Aaron
That’s more a Linux shell question than a Docker question.
env
and printenv
will show your current vars inside container, you can pipe the output into a file.
Oh! I thought the docker export command would work?
Your question makes me wonder about the context of the original question. There is no mentioning of containers, just about “docker setup”, which implies the container runtime itself. Furthermore, it mentions environment variables, but does not set a context about how it would be related to the “docker setup” .
The last response is about exporting an existing container, and does not mention docker setup or environment variables anymore.
I am afraid there is much in your head which you forget to share. The less ambiguous your descriptions are, the more specific responses can be.
Sorry, here is the script I am referring to
#Dynamic DNS
docker run -d \
--restart="unless-stopped" \
-e TZ="Australia/Adelaide" \
-e SERVICE="freedns" \
-e USER="user" \
-e PASSWORD="password" \
-e HOSTNAME="hostname" \
-v ${ROOT}/volumes/DDNS/:/DDNS \
joweisberg/dynamic-dns:latest \
echo export ${HOSTNAME} > /var/lib/docker/volumes/DDNS/host.txt
I am trying to saving the hostname variable in a .txt file for use later on.
or if that can not be done can I put the variables in a .txt file and put them into the container via code?
I am in line with @meyay, what are you trying to do?
You mention to create a txt file, but what do you want to do with it? Maybe share the full big picture.
In general a Docker container is run with ENTRYPOINT as initial starting point, then passing CMD to it. So you may not be able to simply pass a Linux command when starting a container. It depends on the image.
What I trying to do is retrieve the ddns host which, is set via a docker.container so I can use it on another machine, when setting up a vpn it assigns the address in the txt file, rather than the default one.
I highly recommend to not write in the Docker folders directly.
Note that your appended command will overwrite the original (Docker Hub):
CMD ["/bin/bash" "/root/dyndns.sh"]
Maybe check this recent post about a similar topic.
Thanks! Now, how would I populate the environment variables of the contain with the data in the file?
This works to access the hostname inside the running container:
docker run --rm -e HOSTNAME="test" joweisberg/dynamic-dns:latest /bin/bash -c 'echo $HOSTNAME'
I must be missing something, but why don’t you put the hole command into a shell script, and just copy the shell script to the other computer? Depending, how relevant the content of the volume is, you might need to copy its content as well.
After all, it looks like you are assigning the host variable while creating the container yourself. Why would you want to fetch the information from the container, when you assign it yourself on the host?
So I would replace echo $hostname with the path and name of the file containing the data?
I am want to export to my Banana Pi running OpenWRT as the operating system. OpenWRT does not allow the use of the whole SD card 32GB and it is a pain to setup OpenWRT to use an External Hard Drive without accident stopping the BPI from booting. OpenWRT by default only allows for the use of around 90MB (give or take a couple of MBs).
I’m following this topic from the beginning, but let others comment, becuase I didn’t understand anything. And I still don’t. I guess it is partially because of the English language, so if you have any friend who can help you to describe the issue in English, that could be useful.
You got the best answers from @meyay and @bluepuma77 based on what you shared, but we can’t be sure that the answers were answers to your actual question. I don’t understand for example how you came to this conclusion
I don’t even understand what you mean by that. The post you replied to suggested a way to use “echo” to show the content of a variable in the terminal. But the variable was set in the docker run command as a parameter, so it doesn’t make sense that you would want to do that.
Then you talk about exporting again, but you don’t say what you want to export.
mentioning SD cards
As if you were trying to move your entire Docker environment to a new machine where you have more space, but then I don’t get how env files are relevant.
If you can’t describe your issue starting from the beginning so everyone understands what your situation is, this topic will continue for days or weeks and you will still not have an answer just the best guesses.
I think the best description you gave (or the one I believed I understood the most) is
But nothing you shared showed that you try to do anything with generated data. You just tried to use the same variable in a container that you set on the host. Like throwing a ball from your one hand to the other.
You wrote about “another machine”
but it sounds like the VPN creates a txt file, but you just want to create a txt file from another container, the DNS container.
So my interpretation is that you want to access one machine using a domain name from another machine, and you want to know what the IP address is that the freedns service detected for you.
If I’m correct, you shouldn’t even try to echo the hostname, as you know it very well what you set it to. You need the IP address. On the other hand, I wonder why, as you set a domain name already. Also as @bluepuma77 pointed out
So whatever should have a running freends container and use docker exec
to execute a command in it if you need anything from that container.
That’s ll I can add to this topic for now, and I’m not sure how much I understood from the issue.
I receive the following error when Trying to run the following code
CMD ["sh","${ROOT}/volumes/ddns/dyndns.sh", "echo", "$hostname"] \
joweisberg/dynamic-dns:latest
Error:
docker: invalid reference format: repository name (library/CMD) must be lowercase.
Edit:
I have managed to populate the environment variables from the file using:
--env-file ${ROOT}/volumes/ddns/dyndns.sh \
joweisberg/dynamic-dns:latest
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.