boot2docker / boot2docker-cli

boot2docker management utility
Apache License 2.0
339 stars 95 forks source link

|boot2docker up| should mention the replacement to the broken '$(boot2docker shellinit)' pattern #369

Closed edmorley closed 9 years ago

edmorley commented 9 years ago

In #356, single quotes were added around the value assigned to DOCKER_CERT_PATH on Windows.

This results in output like:

[~/src]$ boot2docker shellinit
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\key.pem
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH='C:\Users\Ed\.boot2docker\certs\boot2docker-vm'

Copying and pasting the export lines above and running them by hand (or adding to .profile) works fine.

However when using $(boot2docker shellinit) the quotes actually end up in the value assigned to DOCKER_CERT_PATH, which causes an error when trying to use Docker. eg:

[~/src]$ $(boot2docker shellinit)
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\key.pem
[~/src]$ echo $DOCKER_CERT_PATH
'C:\Users\Ed\.boot2docker\certs\boot2docker-vm'
[~/src]$ docker ps
FATA[0000] Couldn't read ca cert 'C:\Users\Ed\.boot2docker\certs\boot2docker-vm'\ca.pem: open 'C:\Users\Ed\.boot2docker\certs\boot2docker-vm'\ca.pem: The filename, directory name, or volume label syntax is incorrect.

Which leaves a bit of a dilemma: If shellinit doesn't output the quotes, then the manual method breaks, if it does output the quotes, then the $(boot2docker shellinit) method breaks.

It seems the only way to get a value that works for both, is to remove the quotes, and replace all backslashes with double backslashes, eg:

[~/src]$ $(boot2docker shellinit | sed -e s_\'__g -e 's_\\_\\\\_g')
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\key.pem
[~/src]$ echo $DOCKER_CERT_PATH
C:\\Users\\Ed\\.boot2docker\\certs\\boot2docker-vm
[~/src]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS
NAMES
[~/src]$ boot2docker shellinit | sed -e s_\'__g -e 's_\\_\\\\_g'
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\Ed\.boot2docker\certs\boot2docker-vm\key.pem
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=C:\\Users\\Ed\\.boot2docker\\certs\\boot2docker-vm
    export DOCKER_TLS_VERIFY=1
[~/src]$ export DOCKER_CERT_PATH=C:\\Users\\Ed\\.boot2docker\\certs\\boot2docker-vm
[~/src]$ echo $DOCKER_CERT_PATH
C:\Users\Ed\.boot2docker\certs\boot2docker-vm
[~/src]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS
NAMES
edmorley commented 9 years ago

If we do make this change, we'll also need to adjust start.sh in the Windows installer, since it tries to compensate for this already (cc @SvenDowideit), so we'd double up: https://github.com/boot2docker/windows-installer/blob/7bf811d592bddf0b71c534f652fc935f6b3f6914/start.sh#L30-L31

edmorley commented 9 years ago

Ah, it seems like as of boot2docker/boot2docker#786 the new advice is to use: eval "$(boot2docker shellinit)" ...instead, which fixes this and other issues.

Unfortunately the old form is used in a fair number of Stack overflow/how-to guides etc, plus I read the boot2docker readme before they made that change.

To make it clearer, perhaps we could advise to use eval "$(boot2docker shellinit)"in the shellinit text (to part that goes to stderr, like the "Writing foo" messages)?

thaJeztah commented 9 years ago

(Hi again :))

Can you add some more information about the shell / environment you're running this in? (PowerShell, CMD.exe etc.). I know there have been quite some differences in behavior, depending on that.

edmorley commented 9 years ago

I've updated a few more instances of the docs for related projects that were still recommending the old way: docker/docker-py#633 docker/compose#1533