Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

[Windows] A More robuse "Docker Quickstart Terminal" #578

Merged
merged 3 commits into from
Mar 14, 2018
Merged

[Windows] A More robuse "Docker Quickstart Terminal" #578

merged 3 commits into from
Mar 14, 2018

Conversation

somombo
Copy link
Contributor

@somombo somombo commented Oct 3, 2016

Applies to Windows only

This PR is the culmination of a few changes I made in to my docker toolbox build and setup, in order to be able to easily use docker, docker-compose from any terminal in windows i.e. cmd, powershell, git-bash etc

It is quite tedious to only have access to the docker command through the "Docker Quickstart Terminal" (DQT) on the start menu. Moreover DQT is setup to start from the same directory each time; in real day-to-day work, this is almost never the directory you want to be in.

I have made changes to the start.sh script to make it portable. I have also introduced the file docker-terminal.cmd which simply runs the start.sh.. The advantage of docker-terminal is that one can simply open up their project in a specific directory (e.g. with "Open command window here" or "Git bash here") and run docker-terminal from either powershell or command prompt (or git-bash), and this will run the start.sh script: no need to go to you start menu to look for Quickstart Terminal!

What's even better is you only need to run docker-terminal once. Thereafter, you can now use docker, docker-compose etc from powershell or cmd and not rely on having to use the DQT git-bash.

I'd like to invite constructive advice and improvements to this wherever you all feel it can be better!
Thanks!

@powareverb
Copy link

Not sure, but is it worth supporting the new Windows Bash (i.e. Bash on Ubuntu on Windows) rather than "hardcoding" git bash? Also, install location of git bash may be different? Ubunto on Windows bash is at: C:\Windows\System32\bash.exe

@powareverb
Copy link

@somombo did you forget content with that comment? :)

@somombo
Copy link
Contributor Author

somombo commented Oct 6, 2016

@powareverb yup! Sorry must have accidentally hit submit. What I meant to say: Bash on Ubuntu on Windows (BUW) is in its own linux subsystem.. just like it doesn't make sense to have docker toolbox for Linux it therefore wouldn't make sense to have docker toolbox for BUW.. hope this makes sense.. basically Docker is already natively supported on Linux.. so no need for the toolbox layer that emulates linux through a vm

@powareverb
Copy link

powareverb commented Oct 6, 2016

@somombo Yeah, I'm aware it's running as a Linux subsystem. I'm currently using docker-toolbox for the tools, plus BUW and running a custom image in HyperV (though you could just as easily use virtualbox). This is due to the fact I don't like the direction Docker for Windows is headed, but I may have to go back to it yet. But yeah, I can see the PR changes you've made are checking registry, so not useful for BUW.

@somombo
Copy link
Contributor Author

somombo commented Oct 6, 2016

Yep.. I personally intentionally opt not to use the hyperV version of docker because installing hyperV makes it so I can't use virtualbox for my other development stuff e.g. Genymotion Android Emulator which only runs using virtualbox. Apparently, when you install hyperV you can't use any other hypervisors including Vmware's

@somombo somombo changed the title More robuse "Docker Quickstart Terminal" for Windows [Windows] A More robuse "Docker Quickstart Terminal" Oct 12, 2016
@MartinSGill
Copy link

I closed my PR #321 as I believe this is easier to maintain in the long run, than having a dedicated powershell script.

@MartinSGill
Copy link

MartinSGill commented Nov 23, 2016

I'd prefer a single script that gets docker ready to use and injects any environment variables I need into the current terminal.

For example instead of just your single script, maybe add another two such as

  • start-docker.cmd
  • start-docker.ps1
    that call start.sh (or docker-teminal) and then immediately docker-machine env --shell=powershell as appropriate.

e.g. for powershell

(docker-machine env --shell=powershell $vm) | Invoke-Expression

It then becomes much easier as I can now call docker, docker-machine etc from my current terminal.
Having both of those scripts with the same name in the path isn't an issue, as when you invoke start-docker, powershell will default to the ps1 file, and cmd will default to the cmd file.

@somombo
Copy link
Contributor Author

somombo commented Nov 26, 2016

@MartinSGill First of all thank you so much for your support.. I really appreciate the extra effort you put into contributing to this endeavor?

I would like to clarify.. is the sole objective of the changes you have suggested above merely to allow one to be able to run the docker, docker-machine, docker-compose commands from both the Command Prompt and Powershell?

@MartinSGill
Copy link

Yes, that's pretty much it. For my preferred workflow I'd simply like to inject everything I need into the current shell. I still use the Start-DockerMachine script I created in #321 whenever I need docker.

In the powershell world ideally it would be a module that I could load/unload on demand, but the above solution works for me and has the advantages that it's much easier to maintain and keep in line with changes to the primary bash script.

@carlin-q-scott
Copy link

carlin-q-scott commented Jan 9, 2017

Maybe I'm missing something but the built in Docker-Machine env command configures command prompt for invoking docker commands directly by setting the appropriate environment variables.

I'm of the opinion that setup should permanently persist the environment variables so I don't have to run the script every time I open a command prompt.

To modify the env script to accomplish this, it should use setx, not set, on Windows. setx persists the environment variables, set does not. setx has a slightly different syntax, for instance the first variable set would be: setx DOCKER_TLS_VERIFY 1

This also causes docker/kitematic#2050

@somombo
Copy link
Contributor Author

somombo commented Jan 9, 2017

@carlin-q-scott Thanks for emphasizing the importance of that.. This PR in fact already took using SETX into account for precisely the reasons you have mentioned (refer to commit 3c3e184)

@somombo
Copy link
Contributor Author

somombo commented Jan 9, 2017

@MartinSGill Sorry for my late response. I am still not sure what the effective benefit is to having three seperate scripts start-docker.cmd, start-docker.ps1 and start-docker.sh when, as it currently stands, the solution presented by this PR runs just find in all the three environments. Beyond simply making docker work in all three environments, is there perhaps something else I am missing about the extra advantage to having the three script files?

@somombo
Copy link
Contributor Author

somombo commented Feb 27, 2017

Hi @nathanleclaire, this pr's been open half a year. Any feedback?

@nathanleclaire
Copy link
Contributor

Hm, I'm a bit confused by the scope and purpose. This is so that the Toolbox binaries are available in every shell? Could we change the installer to update the system path so that this is possible instead?

@carlin-q-scott
Copy link

carlin-q-scott commented Mar 29, 2017

@nathanleclaire that's what the PR does. I think @MartinSGill was proposing some alternative solution that's more complicated than the PR.

@somombo
Copy link
Contributor Author

somombo commented Mar 29, 2017

@nathanleclaire sorry I took so long to respond for some reason, I didn't realise that you had posted a message.

@carlin-q-scott is correct, in summary, this PR does two things:

  1. Changes the installer to update the system path, thereby replacing the previously hardcoded reference to "C:/Program Files/Docker Toolbox" with more flexible system variable that's set at install-time
  1. Persists the docker environment variables so that users don't have to run the docker-machine env script every time they open command-prompt, powershell or git-bash.

Hope this clarifies things.
Thanks for your timely response!
Let me know if there are any other questions or concerns.

@somombo
Copy link
Contributor Author

somombo commented May 1, 2017

@nathanleclaire ,
Will this be getting reviewed or rejected?

Either way i fine, we just really need some feedback.
Thanks

/cc @JeffDM, @mchiang0610, @lisean106 @FrenchBen

@Serhiy-Shekhovtsov
Copy link

Would be really nice to have such feature. Without it I can't write a single CMD file that will run a DQT, build a machine and run it. I have to run DQT from start menu, then select a bash file with commands.

@Serhiy-Shekhovtsov
Copy link

Serhiy-Shekhovtsov commented Sep 6, 2017

Actually, have found a way to run docker and open shell with one command. For this I have created two files:
up.bat
"C:\Program Files\Git\bin\bash.exe" --login -i -c "cd \"/c/Program Files/Docker Toolbox/\";sh ./start.sh \"sh /[path_to_current_project]/up.sh\""
this file runs bash with commands: change working directory and start DQT with it's own command - to run the up.sh file once the Docker Quickstart Terminal ready.
The up.sh file have docker commands. In my case it's looks like this:

echo "DQT is up, let's start the system!"
cd /[path_to_current_project]/

echo "mounting shared folder"
docker-share mount --transient

echo "building"
docker-compose -f local.yml build

echo "running"
docker-compose -f local.yml up

This way it takes only one command - up.bat to open DQT, build and run the system.

@somombo
Copy link
Contributor Author

somombo commented Sep 6, 2017

/cc @shin-

@ghost
Copy link

ghost commented Sep 21, 2017

As someone that has recently had to switch from Docker for Windows, to Docker Toolbox because I needed to use VirtualBox for Android emulation, this is extremely frustrating. Will this PR be looked at?

@somombo
Copy link
Contributor Author

somombo commented Feb 15, 2018

@shin- are you going to give any kind of response ? Even a negative one is okay. Just some feedback please.

@shin-
Copy link
Contributor

shin- commented Mar 12, 2018

@somombo Sorry, we haven't been very diligent on the Toolbox stuff. Code LGTM, do you mind rebasing against master again?

Chisomo Sakala added 2 commits March 13, 2018 04:55
DOCKER_TOOLBOX_INSTALL_PATH was defined prior, but not added to the users PATH environment variable.
Hence commands such as docker, docker-machine, docker-compose do  not work unless either they are absolutely qualified or the current directory happens
to be %DOCKER_TOOLBOX_INSTALL_PATH%

Signed-off-by: Chisomo Sakala <chisomo.sakala@mombo.solution>
-Removed hard coded reference "/c/Program Files/Docker Toolbox" replacing it with $DOCKER_TOOLBOX_INSTALL_PATH
-Added quotes around string variables that refer to things such as paths that could potentially have spaces after expansion
-Permanently set environment variables DOCKER_HOST, DOCKER_CERT_PATH, DOCKER_MACHINE_NAME, DOCKER_TLS_VERIFY etc using windows SETX instead of the default SET that's provided by `docker-machine env` .

Signed-off-by: Chisomo Sakala <chisomo.sakala@mombo.solution>
…rompt OR Powershell.

This plus the more robust start.sh allows docker commands to be invoked from any terminal in Windows.
The command docker-terminal can also accept regular docker commands such as
- docker-terminal docker ps -a
- docker-terminal docker-compose --version



Signed-off-by: Chisomo Sakala <chisomo.sakala@mombo.solution>
@somombo
Copy link
Contributor Author

somombo commented Mar 13, 2018

Thank you @shin-! I have rebased it. Let me know if there's anything else I can do.

@shin- shin- merged commit c971a9c into docker-archive:master Mar 14, 2018
@shin-
Copy link
Contributor

shin- commented Mar 14, 2018

Thank you! It'll be including in the upcoming 18.03 release.

somombo added a commit to somombo/toolbox that referenced this pull request May 28, 2018
These are variables that would have been permanently set during quick-start
as per issue docker-archive#578

Signed-off-by: Somo S <somo@mombo.solutions>
somombo added a commit to somombo/toolbox that referenced this pull request May 28, 2018
This was meant to have been included as part of
commit c38f335
in pull-request docker-archive#578. But was not due to an oversight.

Signed-off-by: Somo S <somo@mombo.solutions>
@nchawda
Copy link

nchawda commented Jul 4, 2018

Scripts work as explained. And an excellent indeed.

@somombo
Copy link
Contributor Author

somombo commented Jul 4, 2018

Hi all, I have now fixed a bug or rather, an 'oversight', that was introduced here. Kindly help with reviewing #765

shin- pushed a commit that referenced this pull request Jul 23, 2018
These are variables that would have been permanently set during quick-start
as per issue #578

Signed-off-by: Somo S <somo@mombo.solutions>
shin- pushed a commit that referenced this pull request Jul 23, 2018
This was meant to have been included as part of
commit c38f335
in pull-request #578. But was not due to an oversight.

Signed-off-by: Somo S <somo@mombo.solutions>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants