docker / cli

The Docker CLI
Apache License 2.0
4.9k stars 1.92k forks source link

Feature request: better error message for 'docker create network' and other similar incorrect patterns #1986

Open bartolone opened 5 years ago

bartolone commented 5 years ago

Description

When trying the (incorrect) command docker create network ... the user receives a potentially unhelpful error message: Unable to find image 'network:latest' locally (this also applies to config, container, plugin, secret, service, and volume in addition to network). This error message is unintuitive if the user is attempting to create a network and does not redirect them to the correct syntax.

This incorrect pattern seems to be relatively common (see the following examples): https://github.com/jupyterhub/jupyterhub/pull/2632 https://github.com/jwilder/nginx-proxy/issues/502#issuecomment-241283579 *https://github.com/fluencelabs/fluence/blob/master/bootstrap/private_ethereum.md

I propose a new error message to redirect users to the correct pattern as it is much more likely their intent to create a network than to create a container named 'network'. This would likely also necessitate precluding users from naming their containers any one of config, container, network, plugin, secret, service, or volume, but use of those names should probably be discouraged anyway.

I would be happy to take a stab at a PR, but I am not familiar enough with the codebase to be sure of all of the files that would need updating. If someone is willing to help me identify those, I will go ahead and take a shot at it. Also happy to defer if anyone else wants to tackle this, but wanted to get feedback first on if this idea would be supported.

Steps to reproduce the issue:

  1. Type docker create network or substitute any of config, container, plugin, secret, service, and volume in place of network

Describe the results you received: Unable to find image 'network:latest' locally Error response from daemon: pull access denied for network, repository does not exist or may require 'docker login'

Describe the results you expected: Error: cannot create a container named 'network' If you were trying to create a network, see 'docker network create --help'

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:39 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Output of docker info:

Containers: 4
 Running: 4
 Paused: 0
 Stopped: 0
Images: 68
Server Version: 18.09.2
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 6
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: CULL:2WW2:SCNC:EGFF:SS5X:LCJK:NRKW:LFJW:RBUE:JH4T:X3XT:N5E3
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 63
 Goroutines: 101
 System Time: 2019-07-05T19:45:43.012106973Z
 EventsListeners: 3
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
cpuguy83 commented 5 years ago

Makes sense, though error message maybe could be error while creating container: <error>

bartolone commented 5 years ago

I like that, since it makes explicit that what the user typed is the container creation function, when they meant to create a network (or something else).