mirror of
https://github.com/docker/docs.git
synced 2026-04-05 10:48:55 +07:00
This augments the CreateContainer call to detect the AuthConfig header
and use any supplied auth for pull operations. This will allow pulling
of protected image on to specific node during the create operation.
CLI usage example using username/password:
# Calculate the header
REPO_USER=yourusername
read -s PASSWORD
HEADER=$(echo "{\"username\":\"${REPO_USER}\",\"password\":\"${PASSWORD}\"}"|base64 -w 0 )
unset PASSWORD
echo HEADER=$HEADER
# Then add the following to your ~/.docker/config.json
"HttpHeaders": {
"X-Registry-Auth": "<HEADER string from above>"
}
# Now run a private image against swarm:
docker run --rm -it yourprivateimage:latest
CLI usage example using registry tokens: (Required engine 1.10 with new auth token support)
REPO=yourrepo/yourimage
REPO_USER=yourusername
read -s PASSWORD
AUTH_URL=https://auth.docker.io/token
TOKEN=$(curl -s -u "${REPO_USER}:${PASSWORD}" "${AUTH_URL}?scope=repository:${REPO}:pull&service=registry.docker.io" |
jq -r ".token")
HEADER=$(echo "{\"registrytoken\":\"${TOKEN}\"}"|base64 -w 0 )
echo HEADER=$HEADER
# Update the docker config as above, but the token will expire quickly...
Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
99 lines
2.9 KiB
Go
99 lines
2.9 KiB
Go
package cluster
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/samalba/dockerclient"
|
|
)
|
|
|
|
// Cluster is exported
|
|
type Cluster interface {
|
|
// Create a container
|
|
CreateContainer(config *ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (*Container, error)
|
|
|
|
// Remove a container
|
|
RemoveContainer(container *Container, force, volumes bool) error
|
|
|
|
// Return all images
|
|
Images() Images
|
|
|
|
// Return one image matching `IDOrName`
|
|
Image(IDOrName string) *Image
|
|
|
|
// Remove images from the cluster
|
|
RemoveImages(name string, force bool) ([]*dockerclient.ImageDelete, error)
|
|
|
|
// Return all containers
|
|
Containers() Containers
|
|
|
|
// Return container the matching `IDOrName`
|
|
// TODO: remove this method from the interface as we can use
|
|
// cluster.Containers().Get(IDOrName)
|
|
Container(IDOrName string) *Container
|
|
|
|
// Return all networks
|
|
Networks() Networks
|
|
|
|
// Create a network
|
|
CreateNetwork(request *dockerclient.NetworkCreate) (*dockerclient.NetworkCreateResponse, error)
|
|
|
|
// Remove a network from the cluster
|
|
RemoveNetwork(network *Network) error
|
|
|
|
// Create a volume
|
|
CreateVolume(request *dockerclient.VolumeCreateRequest) (*Volume, error)
|
|
|
|
// Return all volumes
|
|
Volumes() []*Volume
|
|
|
|
// Return one volume from the cluster
|
|
Volume(name string) *Volume
|
|
|
|
// Remove volumes from the cluster
|
|
RemoveVolumes(name string) (bool, error)
|
|
|
|
// Pull images
|
|
// `callback` can be called multiple time
|
|
// `where` is where it is being pulled
|
|
// `status` is the current status, like "", "in progress" or "downloaded
|
|
Pull(name string, authConfig *dockerclient.AuthConfig, callback func(where, status string, err error))
|
|
|
|
// Import image
|
|
// `callback` can be called multiple time
|
|
// `where` is where it is being imported
|
|
// `status` is the current status, like "", "in progress" or "imported"
|
|
Import(source string, repository string, tag string, imageReader io.Reader, callback func(where, status string, err error))
|
|
|
|
// Load images
|
|
// `callback` can be called multiple time
|
|
// `what` is what is being loaded
|
|
// `status` is the current status, like "", "in progress" or "loaded"
|
|
Load(imageReader io.Reader, callback func(what, status string, err error))
|
|
|
|
// Return some info about the cluster, like nb or containers / images
|
|
// It is pretty open, so the implementation decides what to return.
|
|
Info() [][]string
|
|
|
|
// Return the total memory of the cluster
|
|
TotalMemory() int64
|
|
|
|
// Return the number of CPUs in the cluster
|
|
TotalCpus() int64
|
|
|
|
// Register an event handler for cluster-wide events.
|
|
RegisterEventHandler(h EventHandler) error
|
|
|
|
// FIXME: remove this method
|
|
// Return a random engine
|
|
RANDOMENGINE() (*Engine, error)
|
|
|
|
// RenameContainer rename a container
|
|
RenameContainer(container *Container, newName string) error
|
|
|
|
// BuildImage build an image
|
|
BuildImage(*dockerclient.BuildImage, io.Writer) error
|
|
|
|
// TagImage tag an image
|
|
TagImage(IDOrName string, repo string, tag string, force bool) error
|
|
}
|