Compare commits

...

8 Commits

Author SHA1 Message Date
David Karlsson e797a96581
Merge a80c7c4117 into a5fb752ecf 2024-09-18 15:34:59 +01:00
Sebastiaan van Stijn a5fb752ecf
Merge pull request #5445 from jsternberg/lowercase-windows-drive
command: change drive to lowercase for wsl path
2024-09-18 12:15:45 +02:00
Laura Brehm 4e64c59d64
Merge pull request #5446 from thaJeztah/codeql_updates
gha: update codeql workflow to go1.22.7
2024-09-18 11:04:32 +01:00
Jonathan A. Sternberg 3472bbc28a
command: change drive to lowercase for wsl path
On Windows, the drive casing doesn't matter outside of WSL. For WSL, the
drives are lowercase. When we're producing a WSL path, lowercase the
drive letter.

Co-authored-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Co-authored-by: Laura Brehm <laurabrehm@hey.com>

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-09-18 10:59:08 +01:00
Laura Brehm 649e564ee0
Merge pull request #5444 from jsternberg/handle-otel-errors
telemetry: pass otel errors to the otel handler for shutdown and force flush
2024-09-18 10:39:55 +01:00
Sebastiaan van Stijn e1213edcc6
gha: update codeql workflow to go1.22.7
commit d7d56599ca updated this
repository to go1.22, but the codeql action didn't specify a
patch version, and was missed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 21:39:56 +02:00
Jonathan A. Sternberg b1956f5073
telemetry: pass otel errors to the otel handler for shutdown and force flush
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-17 10:47:04 -05:00
David Karlsson a80c7c4117 docs: remove unnecessary -itd from examples
The -itd options, probably used to keep the tty container running in the
background, is not necessary for these examples. Updated the examples to
remove the unnecessary flags. Also, changed the example image from
busybox to nginx.

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2024-07-01 13:47:17 +02:00
12 changed files with 66 additions and 33 deletions

View File

@ -67,7 +67,7 @@ jobs:
name: Update Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: 1.22.7
-
name: Initialize CodeQL
uses: github/codeql-action/init@v3

View File

@ -180,7 +180,7 @@ func toWslPath(s string) string {
if !ok {
return ""
}
return fmt.Sprintf("mnt/%s%s", drive, p)
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
}
func parseUNCPath(s string) (drive, p string, ok bool) {

View File

@ -1,6 +1,7 @@
package command
import (
"io/fs"
"net/url"
"testing"
"testing/fstest"
@ -9,21 +10,48 @@ import (
)
func TestWslSocketPath(t *testing.T) {
u, err := url.Parse("unix:////./c:/my/file/path")
assert.NilError(t, err)
// Ensure host is empty.
assert.Equal(t, u.Host, "")
// Use a filesystem where the WSL path exists.
fs := fstest.MapFS{
"mnt/c/my/file/path": {},
testCases := []struct {
doc string
fs fs.FS
url string
expected string
}{
{
doc: "filesystem where WSL path does not exist",
fs: fstest.MapFS{
"my/file/path": {},
},
url: "unix:////./c:/my/file/path",
expected: "",
},
{
doc: "filesystem where WSL path exists",
fs: fstest.MapFS{
"mnt/c/my/file/path": {},
},
url: "unix:////./c:/my/file/path",
expected: "/mnt/c/my/file/path",
},
{
doc: "filesystem where WSL path exists uppercase URL",
fs: fstest.MapFS{
"mnt/c/my/file/path": {},
},
url: "unix:////./C:/my/file/path",
expected: "/mnt/c/my/file/path",
},
}
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
// Use a filesystem where the WSL path doesn't exist.
fs = fstest.MapFS{
"my/file/path": {},
for _, tc := range testCases {
t.Run(tc.doc, func(t *testing.T) {
u, err := url.Parse(tc.url)
assert.NilError(t, err)
// Ensure host is empty.
assert.Equal(t, u.Host, "")
result := wslSocketPath(u.Path, tc.fs)
assert.Equal(t, result, tc.expected)
})
}
assert.Equal(t, wslSocketPath(u.Path, fs), "")
}

View File

@ -9,6 +9,7 @@ import (
"github.com/docker/cli/cli/version"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
metric.WithAttributes(cmdStatusAttrs...),
)
if mp, ok := mp.(MeterProvider); ok {
mp.ForceFlush(ctx)
if err := mp.ForceFlush(ctx); err != nil {
otel.Handle(err)
}
}
}
}

View File

@ -358,7 +358,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
mp := dockerCli.MeterProvider()
if mp, ok := mp.(command.MeterProvider); ok {
defer mp.Shutdown(ctx)
if err := mp.Shutdown(ctx); err != nil {
otel.Handle(err)
}
} else {
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
}

View File

@ -725,7 +725,7 @@ to the `my-net` network.
```console
$ docker network create my-net
$ docker run -itd --network=my-net busybox
$ docker run --network=my-net nginx
```
You can also choose the IP addresses for the container with `--ip` and `--ip6`
@ -734,7 +734,7 @@ static IP to containers, you must specify subnet block for the network.
```console
$ docker network create --subnet 192.0.2.0/24 my-net
$ docker run -itd --network=my-net --ip=192.0.2.69 busybox
$ docker run --network=my-net --ip=192.0.2.69 nginx
```
To connect the container to more than one network, repeat the `--network` option.
@ -742,7 +742,7 @@ To connect the container to more than one network, repeat the `--network` option
```console
$ docker network create --subnet 192.0.2.0/24 my-net1
$ docker network create --subnet 192.0.3.0/24 my-net2
$ docker run -itd --network=my-net1 --network=my-net2 busybox
$ docker run --network=my-net1 --network=my-net2 nginx
```
To specify options when connecting to more than one network, use the extended syntax
@ -762,7 +762,7 @@ for the `--network` flag. Comma-separated options that can be specified in the e
```console
$ docker network create --subnet 192.0.2.0/24 my-net1
$ docker network create --subnet 192.0.3.0/24 my-net2
$ docker run -itd --network=name=my-net1,ip=192.0.2.42 --network=name=my-net2,ip=192.0.3.42 busybox
$ docker run --network=name=my-net1,ip=192.0.2.42 --network=name=my-net2,ip=192.0.3.42 nginx
```
`sysctl` settings that start with `net.ipv4.`, `net.ipv6.` or `net.mpls.` can be
@ -777,7 +777,7 @@ assigns the IPv4 address `192.0.2.42`.
```console
$ docker network create --subnet 192.0.2.0/24 my-net
$ docker run -itd --network=name=my-net,\"driver-opt=com.docker.network.endpoint.sysctls=net.ipv4.conf.IFNAME.log_martians=1,net.ipv4.conf.IFNAME.forwarding=0\",ip=192.0.2.42 busybox
$ docker run --network=name=my-net,\"driver-opt=com.docker.network.endpoint.sysctls=net.ipv4.conf.IFNAME.log_martians=1,net.ipv4.conf.IFNAME.forwarding=0\",ip=192.0.2.42 nginx
```
> [!NOTE]

View File

@ -37,7 +37,7 @@ You can also use the `docker run --network=<network-name>` option to start a
container and immediately connect it to a network.
```console
$ docker run -itd --network=multi-host-network busybox
$ docker run --network=multi-host-network nginx
```
### <a name="ip"></a> Specify the IP address a container will use on a given network (--ip)

View File

@ -84,10 +84,10 @@ for more information about different endpoint modes.
### Connect containers
When you start a container, use the `--network` flag to connect it to a network.
This example adds the `busybox` container to the `mynet` network:
This example adds the `nginx` container to the `mynet` network:
```console
$ docker run -itd --network=mynet busybox
$ docker run --network=mynet nginx
```
If you want to add a container to a network after the container is already

View File

@ -25,10 +25,10 @@ all results in a JSON object.
Connect two containers to the default `bridge` network:
```console
$ sudo docker run -itd --name=container1 busybox
$ sudo docker run -d --name=container1 nginx
f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27
$ sudo docker run -itd --name=container2 busybox
$ sudo docker run -d --name=container2 nginx
bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727
```

View File

@ -9,7 +9,7 @@ $ docker network connect multi-host-network container1
You can also use the `docker run --network=<network-name>` option to start a container and immediately connect it to a network.
```console
$ docker run -itd --network=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 busybox
$ docker run --network=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 nginx
```
You can pause, restart, and stop containers that are connected to a network.

View File

@ -51,10 +51,10 @@ for more information about different endpoint modes.
## Connect containers
When you start a container, use the `--network` flag to connect it to a network.
This example adds the `busybox` container to the `mynet` network:
This example adds the `nginx` container to the `mynet` network:
```console
$ docker run -itd --network=mynet busybox
$ docker run -d --network=mynet nginx
```
If you want to add a container to a network after the container is already

View File

@ -1,10 +1,10 @@
Returns information about one or more networks. By default, this command renders all results in a JSON object. For example, if you connect two containers to the default `bridge` network:
```console
$ sudo docker run -itd --name=container1 busybox
$ sudo docker run -d --name=container1 nginx
f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27
$ sudo docker run -itd --name=container2 busybox
$ sudo docker run -d --name=container2 nginx
bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727
```