mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d73740343 | ||
|
|
a148301a03 | ||
|
|
caaea2e08f | ||
|
|
de7ce7c10d | ||
|
|
c903a6baf8 | ||
|
|
4205b6bb1d | ||
|
|
ca6409059d | ||
|
|
459a2867dd | ||
|
|
28d5b2c15a | ||
|
|
6d2e3d2ec0 | ||
|
|
a4e6025cc1 | ||
|
|
56431d3130 | ||
|
|
5324614410 | ||
|
|
fc788956c5 | ||
|
|
2ed1092dad | ||
|
|
194fca8347 | ||
|
|
2c14d3949d | ||
|
|
2a53717e8f | ||
|
|
97247c5c73 | ||
|
|
b2084a9c59 | ||
|
|
9a39404127 | ||
|
|
fc864d2f0f | ||
|
|
dcab408f6a | ||
|
|
faafbf2118 | ||
|
|
881fdc59ed | ||
|
|
560a74af15 | ||
|
|
b6165daa77 | ||
|
|
ae0d555022 | ||
|
|
7ff2e6b797 | ||
|
|
92939569ab | ||
|
|
d97fff60a9 | ||
|
|
33ea1483d5 | ||
|
|
6cbc7757b2 | ||
|
|
75d2244023 | ||
|
|
08e5f12954 | ||
|
|
e33ba9b36d | ||
|
|
a5fe6f8af4 | ||
|
|
8f829eb5e4 | ||
|
|
044bdc1b5f | ||
|
|
c00d1a6ebe | ||
|
|
11550c6063 | ||
|
|
dc1fa0745f | ||
|
|
3bac27f240 | ||
|
|
286ce266b4 | ||
|
|
aa42c6f2a2 | ||
|
|
7181edf4b2 | ||
|
|
c7985808ae | ||
|
|
83db1f36e3 | ||
|
|
24ddfe3f25 | ||
|
|
b76d6120ac | ||
|
|
cd0de83917 | ||
|
|
e84306ca61 | ||
|
|
f65327555e | ||
|
|
7aa0d11171 | ||
|
|
54af053623 | ||
|
|
5b33b2463a | ||
|
|
2127f8d6ad | ||
|
|
2897cb0476 | ||
|
|
fe0c0c208c | ||
|
|
522f399d68 | ||
|
|
326faec664 | ||
|
|
28a30eda88 | ||
|
|
387eb5295a | ||
|
|
f3cc1d985e | ||
|
|
cfb8cbe521 | ||
|
|
582a9e0a67 | ||
|
|
a48799016a | ||
|
|
dce82bc856 | ||
|
|
90ffcda055 | ||
|
|
6ae3800151 | ||
|
|
54db18625a | ||
|
|
235ae9cd43 | ||
|
|
444f7020cb | ||
|
|
525080100d | ||
|
|
e5fa4a4956 | ||
|
|
4f9443927e | ||
|
|
d9670f4275 | ||
|
|
3d8da80611 | ||
|
|
7d6ff7be12 | ||
|
|
d3b9733507 | ||
|
|
df23a1e675 | ||
|
|
bb4b35a892 | ||
|
|
194f487749 | ||
|
|
9775f0bd14 | ||
|
|
a05bfb246f | ||
|
|
b438565609 | ||
|
|
ffd9e06deb | ||
|
|
88ef309a94 | ||
|
|
c5f15dcd3d | ||
|
|
d8e60b797f | ||
|
|
064101d82e | ||
|
|
a3293ed854 | ||
|
|
3d1bc2660c | ||
|
|
48fd8ae79c | ||
|
|
c167d603f2 | ||
|
|
bfb65b733a | ||
|
|
ae72c2f4d6 | ||
|
|
0146f65a44 | ||
|
|
deb9963e6e | ||
|
|
d7b01c049d | ||
|
|
92e4a51965 | ||
|
|
3c7bca7a21 | ||
|
|
1b5ab5afe0 | ||
|
|
4e576f047f | ||
|
|
8dc2ad2c06 | ||
|
|
58ce66e553 | ||
|
|
1f23b4caae | ||
|
|
4dab2fccd3 | ||
|
|
a7d7a06655 | ||
|
|
9ebfcc9a15 | ||
|
|
70d2123efd | ||
|
|
2cd00a47a5 | ||
|
|
e3f0429859 | ||
|
|
d42c10aa09 | ||
|
|
ecb64be6a8 | ||
|
|
83bc5b7435 | ||
|
|
31c98bdaaf | ||
|
|
59835135c5 | ||
|
|
13f1939a63 | ||
|
|
cf35e8ed81 | ||
|
|
0f135ad7f3 | ||
|
|
056698b676 | ||
|
|
b4198de6bf | ||
|
|
800b401f0b | ||
|
|
a3ccec197e | ||
|
|
3a9ef5f9bb | ||
|
|
1b0b962b43 |
@@ -1,3 +1,8 @@
|
|||||||
|
# This file lists all individuals having contributed content to the repository.
|
||||||
|
# If you're submitting a patch, please add your name here in alphabetical order as part of the patch.
|
||||||
|
#
|
||||||
|
# For a list of active project maintainers, see the MAINTAINERS file.
|
||||||
|
#
|
||||||
Al Tobey <al@ooyala.com>
|
Al Tobey <al@ooyala.com>
|
||||||
Alexey Shamrin <shamrin@gmail.com>
|
Alexey Shamrin <shamrin@gmail.com>
|
||||||
Andrea Luzzardi <aluzzardi@gmail.com>
|
Andrea Luzzardi <aluzzardi@gmail.com>
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.3.4 (2013-05-30)
|
||||||
|
+ Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile
|
||||||
|
+ Builder: 'docker build -t FOO' applies the tag FOO to the newly built container.
|
||||||
|
+ Runtime: interactive TTYs correctly handle window resize
|
||||||
|
* Runtime: fix how configuration is merged between layers
|
||||||
|
+ Remote API: split stdout and stderr on 'docker run'
|
||||||
|
+ Remote API: optionally listen on a different IP and port (use at your own risk)
|
||||||
|
* Documentation: improved install instructions.
|
||||||
|
|
||||||
## 0.3.3 (2013-05-23)
|
## 0.3.3 (2013-05-23)
|
||||||
- Registry: Fix push regression
|
- Registry: Fix push regression
|
||||||
- Various bugfixes
|
- Various bugfixes
|
||||||
|
|||||||
+71
-4
@@ -1,9 +1,6 @@
|
|||||||
# Contributing to Docker
|
# Contributing to Docker
|
||||||
|
|
||||||
Want to hack on Docker? Awesome! There are instructions to get you
|
Want to hack on Docker? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels
|
||||||
started on the website: http://docker.io/gettingstarted.html
|
|
||||||
|
|
||||||
They are probably not perfect, please let us know if anything feels
|
|
||||||
wrong or incomplete.
|
wrong or incomplete.
|
||||||
|
|
||||||
## Contribution guidelines
|
## Contribution guidelines
|
||||||
@@ -91,3 +88,73 @@ Add your name to the AUTHORS file, but make sure the list is sorted and your
|
|||||||
name and email address match your git configuration. The AUTHORS file is
|
name and email address match your git configuration. The AUTHORS file is
|
||||||
regenerated occasionally from the git commit history, so a mismatch may result
|
regenerated occasionally from the git commit history, so a mismatch may result
|
||||||
in your changes being overwritten.
|
in your changes being overwritten.
|
||||||
|
|
||||||
|
|
||||||
|
## Decision process
|
||||||
|
|
||||||
|
### How are decisions made?
|
||||||
|
|
||||||
|
Short answer: with pull requests to the docker repository.
|
||||||
|
|
||||||
|
Docker is an open-source project with an open design philosophy. This means that the repository is the source of truth for EVERY aspect of the project,
|
||||||
|
including its philosophy, design, roadmap and APIs. *If it's part of the project, it's in the repo. It's in the repo, it's part of the project.*
|
||||||
|
|
||||||
|
As a result, all decisions can be expressed as changes to the repository. An implementation change is a change to the source code. An API change is a change to
|
||||||
|
the API specification. A philosophy change is a change to the philosophy manifesto. And so on.
|
||||||
|
|
||||||
|
All decisions affecting docker, big and small, follow the same 3 steps:
|
||||||
|
|
||||||
|
* Step 1: Open a pull request. Anyone can do this.
|
||||||
|
|
||||||
|
* Step 2: Discuss the pull request. Anyone can do this.
|
||||||
|
|
||||||
|
* Step 3: Accept or refuse a pull request. The relevant maintainer does this (see below "Who decides what?")
|
||||||
|
|
||||||
|
|
||||||
|
### Who decides what?
|
||||||
|
|
||||||
|
So all decisions are pull requests, and the relevant maintainer makes the decision by accepting or refusing the pull request.
|
||||||
|
But how do we identify the relevant maintainer for a given pull request?
|
||||||
|
|
||||||
|
Docker follows the timeless, highly efficient and totally unfair system known as [Benevolent dictator for life](http://en.wikipedia.org/wiki/Benevolent_Dictator_for_Life),
|
||||||
|
with yours truly, Solomon Hykes, in the role of BDFL.
|
||||||
|
This means that all decisions are made by default by me. Since making every decision myself would be highly unscalable, in practice decisions are spread across multiple maintainers.
|
||||||
|
|
||||||
|
The relevant maintainer for a pull request is assigned in 3 steps:
|
||||||
|
|
||||||
|
* Step 1: Determine the subdirectory affected by the pull request. This might be src/registry, docs/source/api, or any other part of the repo.
|
||||||
|
|
||||||
|
* Step 2: Find the MAINTAINERS file which affects this directory. If the directory itself does not have a MAINTAINERS file, work your way up the the repo hierarchy until you find one.
|
||||||
|
|
||||||
|
* Step 3: The first maintainer listed is the primary maintainer. The pull request is assigned to him. He may assign it to other listed maintainers, at his discretion.
|
||||||
|
|
||||||
|
|
||||||
|
### I'm a maintainer, should I make pull requests too?
|
||||||
|
|
||||||
|
Primary maintainers are not required to create pull requests when changing their own subdirectory, but secondary maintainers are.
|
||||||
|
|
||||||
|
### Who assigns maintainers?
|
||||||
|
|
||||||
|
Solomon.
|
||||||
|
|
||||||
|
### How can I become a maintainer?
|
||||||
|
|
||||||
|
* Step 1: learn the component inside out
|
||||||
|
* Step 2: make yourself useful by contributing code, bugfixes, support etc.
|
||||||
|
* Step 3: volunteer on the irc channel (#docker@freenode)
|
||||||
|
|
||||||
|
Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available.
|
||||||
|
You don't have to be a maintainer to make a difference on the project!
|
||||||
|
|
||||||
|
### What are a maintainer's responsibility?
|
||||||
|
|
||||||
|
It is every maintainer's responsibility to:
|
||||||
|
|
||||||
|
* 1) Expose a clear roadmap for improving their component.
|
||||||
|
* 2) Deliver prompt feedback and decisions on pull requests.
|
||||||
|
* 3) Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list.
|
||||||
|
* 4) Make sure their component respects the philosophy, design and roadmap of the project.
|
||||||
|
|
||||||
|
### How is this process changed?
|
||||||
|
|
||||||
|
Just like everything else: by making a pull request :)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Solomon Hykes <solomon@dotcloud.com>
|
||||||
|
Guillaume Charmes <guillaume@dotcloud.com>
|
||||||
|
Victor Vieux <victor@dotcloud.com>
|
||||||
|
api.go: Victor Vieux <victor@dotcloud.com>
|
||||||
|
Vagrantfile: Daniel Mizyrycki <daniel@dotcloud.com>
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
## Spec for data volumes
|
|
||||||
|
|
||||||
Spec owner: Solomon Hykes <solomon@dotcloud.com>
|
|
||||||
|
|
||||||
Data volumes (issue #111) are a much-requested feature which trigger much discussion and debate. Below is the current authoritative spec for implementing data volumes.
|
|
||||||
This spec will be deprecated once the feature is fully implemented.
|
|
||||||
|
|
||||||
Discussion, requests, trolls, demands, offerings, threats and other forms of supplications concerning this spec should be addressed to Solomon here: https://github.com/dotcloud/docker/issues/111
|
|
||||||
|
|
||||||
|
|
||||||
### 1. Creating data volumes
|
|
||||||
|
|
||||||
At container creation, parts of a container's filesystem can be mounted as separate data volumes. Volumes are defined with the -v flag.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ docker run -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres
|
|
||||||
```
|
|
||||||
|
|
||||||
In this example, a new container is created from the 'postgres' image. At the same time, docker creates 2 new data volumes: one will be mapped to the container at /var/lib/postgres, the other at /var/log.
|
|
||||||
|
|
||||||
2 important notes:
|
|
||||||
|
|
||||||
1) Volumes don't have top-level names. At no point does the user provide a name, or is a name given to him. Volumes are identified by the path at which they are mounted inside their container.
|
|
||||||
|
|
||||||
2) The user doesn't choose the source of the volume. Docker only mounts volumes it created itself, in the same way that it only runs containers that it created itself. That is by design.
|
|
||||||
|
|
||||||
|
|
||||||
### 2. Sharing data volumes
|
|
||||||
|
|
||||||
Instead of creating its own volumes, a container can share another container's volumes. For example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ docker run --volumes-from $OTHER_CONTAINER_ID postgres /usr/local/bin/postgres-backup
|
|
||||||
```
|
|
||||||
|
|
||||||
In this example, a new container is created from the 'postgres' example. At the same time, docker will *re-use* the 2 data volumes created in the previous example. One volume will be mounted on the /var/lib/postgres of *both* containers, and the other will be mounted on the /var/log of both containers.
|
|
||||||
|
|
||||||
### 3. Under the hood
|
|
||||||
|
|
||||||
Docker stores volumes in /var/lib/docker/volumes. Each volume receives a globally unique ID at creation, and is stored at /var/lib/docker/volumes/ID.
|
|
||||||
|
|
||||||
At creation, volumes are attached to a single container - the source of truth for this mapping will be the container's configuration.
|
|
||||||
|
|
||||||
Mounting a volume consists of calling "mount --bind" from the volume's directory to the appropriate sub-directory of the container mountpoint. This may be done by Docker itself, or farmed out to lxc (which supports mount-binding) if possible.
|
|
||||||
|
|
||||||
|
|
||||||
### 4. Backups, transfers and other volume operations
|
|
||||||
|
|
||||||
Volumes sometimes need to be backed up, transfered between hosts, synchronized, etc. These operations typically are application-specific or site-specific, eg. rsync vs. S3 upload vs. replication vs...
|
|
||||||
|
|
||||||
Rather than attempting to implement all these scenarios directly, Docker will allow for custom implementations using an extension mechanism.
|
|
||||||
|
|
||||||
### 5. Custom volume handlers
|
|
||||||
|
|
||||||
Docker allows for arbitrary code to be executed against a container's volumes, to implement any custom action: backup, transfer, synchronization across hosts, etc.
|
|
||||||
|
|
||||||
Here's an example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ DB=$(docker run -d -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres)
|
|
||||||
|
|
||||||
$ BACKUP_JOB=$(docker run -d --volumes-from $DB shykes/backuper /usr/local/bin/backup-postgres --s3creds=$S3CREDS)
|
|
||||||
|
|
||||||
$ docker wait $BACKUP_JOB
|
|
||||||
```
|
|
||||||
|
|
||||||
Congratulations, you just implemented a custom volume handler, using Docker's built-in ability to 1) execute arbitrary code and 2) share volumes between containers.
|
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const API_VERSION = 1.0
|
const API_VERSION = 1.1
|
||||||
|
|
||||||
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
||||||
conn, _, err := w.(http.Hijacker).Hijack()
|
conn, _, err := w.(http.Hijacker).Hijack()
|
||||||
@@ -33,6 +33,13 @@ func parseForm(r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMultipartForm(r *http.Request) error {
|
||||||
|
if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func httpError(w http.ResponseWriter, err error) {
|
func httpError(w http.ResponseWriter, err error) {
|
||||||
if strings.HasPrefix(err.Error(), "No such") {
|
if strings.HasPrefix(err.Error(), "No such") {
|
||||||
http.Error(w, err.Error(), http.StatusNotFound)
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
@@ -48,6 +55,7 @@ func writeJson(w http.ResponseWriter, b []byte) {
|
|||||||
w.Write(b)
|
w.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Use stvconv.ParseBool() instead?
|
||||||
func getBoolParam(value string) (bool, error) {
|
func getBoolParam(value string) (bool, error) {
|
||||||
if value == "1" || strings.ToLower(value) == "true" {
|
if value == "1" || strings.ToLower(value) == "true" {
|
||||||
return true, nil
|
return true, nil
|
||||||
@@ -59,7 +67,16 @@ func getBoolParam(value string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
b, err := json.Marshal(srv.registry.GetAuthConfig())
|
// FIXME: Handle multiple login at once
|
||||||
|
// FIXME: return specific error code if config file missing?
|
||||||
|
authConfig, err := auth.LoadConfig(srv.runtime.root)
|
||||||
|
if err != nil {
|
||||||
|
if err != auth.ErrConfigFileMissing {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
authConfig = &auth.AuthConfig{}
|
||||||
|
}
|
||||||
|
b, err := json.Marshal(&auth.AuthConfig{Username: authConfig.Username, Email: authConfig.Email})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,13 +85,21 @@ func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
// FIXME: Handle multiple login at once
|
||||||
config := &auth.AuthConfig{}
|
config := &auth.AuthConfig{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(config); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Username == srv.registry.GetAuthConfig().Username {
|
authConfig, err := auth.LoadConfig(srv.runtime.root)
|
||||||
config.Password = srv.registry.GetAuthConfig().Password
|
if err != nil {
|
||||||
|
if err != auth.ErrConfigFileMissing {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
authConfig = &auth.AuthConfig{}
|
||||||
|
}
|
||||||
|
if config.Username == authConfig.Username {
|
||||||
|
config.Password = authConfig.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
newAuthConfig := auth.NewAuthConfig(config.Username, config.Password, config.Email, srv.runtime.root)
|
newAuthConfig := auth.NewAuthConfig(config.Username, config.Password, config.Email, srv.runtime.root)
|
||||||
@@ -82,7 +107,6 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
srv.registry.ResetClient(newAuthConfig)
|
|
||||||
|
|
||||||
if status != "" {
|
if status != "" {
|
||||||
b, err := json.Marshal(&ApiAuth{Status: status})
|
b, err := json.Marshal(&ApiAuth{Status: status})
|
||||||
@@ -205,7 +229,7 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainersPs(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -290,7 +314,10 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht
|
|||||||
|
|
||||||
if image != "" { //pull
|
if image != "" { //pull
|
||||||
registry := r.Form.Get("registry")
|
registry := r.Form.Get("registry")
|
||||||
if err := srv.ImagePull(image, tag, registry, w); err != nil {
|
if version > 1.0 {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
if err := srv.ImagePull(image, tag, registry, w, version > 1.0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else { //import
|
} else { //import
|
||||||
@@ -331,9 +358,15 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht
|
|||||||
}
|
}
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
|
|
||||||
if err := srv.ImageInsert(name, url, path, w); err != nil {
|
imgId, err := srv.ImageInsert(name, url, path, w)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
b, err := json.Marshal(&ApiId{Id: imgId})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
writeJson(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,6 +518,28 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postContainersResize(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
if err := parseForm(r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
height, err := strconv.Atoi(r.Form.Get("h"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
width, err := strconv.Atoi(r.Form.Get("w"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if vars == nil {
|
||||||
|
return fmt.Errorf("Missing parameter")
|
||||||
|
}
|
||||||
|
name := vars["name"]
|
||||||
|
if err := srv.ContainerResize(name, height, width); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -515,6 +570,10 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
|
|||||||
}
|
}
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
|
|
||||||
|
if _, err := srv.ContainerInspect(name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
in, out, err := hijackServer(w)
|
in, out, err := hijackServer(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -587,6 +646,39 @@ func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
if err := r.ParseMultipartForm(4096); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
remote := r.FormValue("t")
|
||||||
|
tag := ""
|
||||||
|
if strings.Contains(remote, ":") {
|
||||||
|
remoteParts := strings.Split(remote, ":")
|
||||||
|
tag = remoteParts[1]
|
||||||
|
remote = remoteParts[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerfile, _, err := r.FormFile("Dockerfile")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
context, _, err := r.FormFile("Context")
|
||||||
|
if err != nil {
|
||||||
|
if err != http.ErrMissingFile {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b := NewBuildFile(srv, utils.NewWriteFlusher(w))
|
||||||
|
if id, err := b.Build(dockerfile, context); err != nil {
|
||||||
|
fmt.Fprintf(w, "Error build: %s\n", err)
|
||||||
|
} else if remote != "" {
|
||||||
|
srv.runtime.repositories.Set(remote, tag, id, false)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ListenAndServe(addr string, srv *Server, logging bool) error {
|
func ListenAndServe(addr string, srv *Server, logging bool) error {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
log.Printf("Listening for HTTP on %s\n", addr)
|
log.Printf("Listening for HTTP on %s\n", addr)
|
||||||
@@ -601,7 +693,8 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
|||||||
"/images/search": getImagesSearch,
|
"/images/search": getImagesSearch,
|
||||||
"/images/{name:.*}/history": getImagesHistory,
|
"/images/{name:.*}/history": getImagesHistory,
|
||||||
"/images/{name:.*}/json": getImagesByName,
|
"/images/{name:.*}/json": getImagesByName,
|
||||||
"/containers/ps": getContainersPs,
|
"/containers/ps": getContainersJson,
|
||||||
|
"/containers/json": getContainersJson,
|
||||||
"/containers/{name:.*}/export": getContainersExport,
|
"/containers/{name:.*}/export": getContainersExport,
|
||||||
"/containers/{name:.*}/changes": getContainersChanges,
|
"/containers/{name:.*}/changes": getContainersChanges,
|
||||||
"/containers/{name:.*}/json": getContainersByName,
|
"/containers/{name:.*}/json": getContainersByName,
|
||||||
@@ -609,6 +702,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
|||||||
"POST": {
|
"POST": {
|
||||||
"/auth": postAuth,
|
"/auth": postAuth,
|
||||||
"/commit": postCommit,
|
"/commit": postCommit,
|
||||||
|
"/build": postBuild,
|
||||||
"/images/create": postImagesCreate,
|
"/images/create": postImagesCreate,
|
||||||
"/images/{name:.*}/insert": postImagesInsert,
|
"/images/{name:.*}/insert": postImagesInsert,
|
||||||
"/images/{name:.*}/push": postImagesPush,
|
"/images/{name:.*}/push": postImagesPush,
|
||||||
@@ -620,6 +714,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
|||||||
"/containers/{name:.*}/start": postContainersStart,
|
"/containers/{name:.*}/start": postContainersStart,
|
||||||
"/containers/{name:.*}/stop": postContainersStop,
|
"/containers/{name:.*}/stop": postContainersStop,
|
||||||
"/containers/{name:.*}/wait": postContainersWait,
|
"/containers/{name:.*}/wait": postContainersWait,
|
||||||
|
"/containers/{name:.*}/resize": postContainersResize,
|
||||||
"/containers/{name:.*}/attach": postContainersAttach,
|
"/containers/{name:.*}/attach": postContainersAttach,
|
||||||
},
|
},
|
||||||
"DELETE": {
|
"DELETE": {
|
||||||
@@ -662,6 +757,5 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
|||||||
r.Path(localRoute).Methods(localMethod).HandlerFunc(f)
|
r.Path(localRoute).Methods(localMethod).HandlerFunc(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.ListenAndServe(addr, r)
|
return http.ListenAndServe(addr, r)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-13
@@ -26,8 +26,7 @@ func TestGetAuth(t *testing.T) {
|
|||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
registry: registry.NewRegistry(runtime.root),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
@@ -56,7 +55,7 @@ func TestGetAuth(t *testing.T) {
|
|||||||
t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
|
t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
newAuthConfig := srv.registry.GetAuthConfig()
|
newAuthConfig := registry.NewRegistry(runtime.root).GetAuthConfig(false)
|
||||||
if newAuthConfig.Username != authConfig.Username ||
|
if newAuthConfig.Username != authConfig.Username ||
|
||||||
newAuthConfig.Email != authConfig.Email {
|
newAuthConfig.Email != authConfig.Email {
|
||||||
t.Fatalf("The auth configuration hasn't been set correctly")
|
t.Fatalf("The auth configuration hasn't been set correctly")
|
||||||
@@ -247,8 +246,7 @@ func TestGetImagesSearch(t *testing.T) {
|
|||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
registry: registry.NewRegistry(runtime.root),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
@@ -318,7 +316,7 @@ func TestGetImagesByName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainersPs(t *testing.T) {
|
func TestGetContainersJson(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -336,13 +334,13 @@ func TestGetContainersPs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil)
|
req, err := http.NewRequest("GET", "/containers/json?all=1", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getContainersPs(srv, API_VERSION, r, req, nil); err != nil {
|
if err := getContainersJson(srv, API_VERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
containers := []ApiContainers{}
|
containers := []ApiContainers{}
|
||||||
@@ -504,15 +502,16 @@ func TestPostAuth(t *testing.T) {
|
|||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
registry: registry.NewRegistry(runtime.root),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
authConfigOrig := &auth.AuthConfig{
|
config := &auth.AuthConfig{
|
||||||
Username: "utest",
|
Username: "utest",
|
||||||
Email: "utest@yopmail.com",
|
Email: "utest@yopmail.com",
|
||||||
}
|
}
|
||||||
srv.registry.ResetClient(authConfigOrig)
|
|
||||||
|
authStr := auth.EncodeAuth(config)
|
||||||
|
auth.SaveConfig(runtime.root, authStr, config.Email)
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil {
|
if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil {
|
||||||
@@ -524,7 +523,7 @@ func TestPostAuth(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if authConfig.Username != authConfigOrig.Username || authConfig.Email != authConfigOrig.Email {
|
if authConfig.Username != config.Username || authConfig.Email != config.Email {
|
||||||
t.Errorf("The retrieve auth mismatch with the one set.")
|
t.Errorf("The retrieve auth mismatch with the one set.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-1
@@ -2,6 +2,7 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -31,6 +32,20 @@ func (compression *Compression) Flag() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (compression *Compression) Extension() string {
|
||||||
|
switch *compression {
|
||||||
|
case Uncompressed:
|
||||||
|
return "tar"
|
||||||
|
case Bzip2:
|
||||||
|
return "tar.bz2"
|
||||||
|
case Gzip:
|
||||||
|
return "tar.gz"
|
||||||
|
case Xz:
|
||||||
|
return "tar.xz"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func Tar(path string, compression Compression) (io.Reader, error) {
|
func Tar(path string, compression Compression) (io.Reader, error) {
|
||||||
cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".")
|
cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".")
|
||||||
return CmdStream(cmd)
|
return CmdStream(cmd)
|
||||||
@@ -41,7 +56,7 @@ func Untar(archive io.Reader, path string) error {
|
|||||||
cmd.Stdin = archive
|
cmd.Stdin = archive
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(err.Error() + ": " + string(output))
|
return fmt.Errorf("%s: %s", err, output)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../registry/MAINTAINERS
|
||||||
+15
-4
@@ -3,6 +3,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -17,6 +18,12 @@ const CONFIGFILE = ".dockercfg"
|
|||||||
// the registry server we want to login against
|
// the registry server we want to login against
|
||||||
const INDEX_SERVER = "https://index.docker.io/v1"
|
const INDEX_SERVER = "https://index.docker.io/v1"
|
||||||
|
|
||||||
|
//const INDEX_SERVER = "http://indexstaging-docker.dotcloud.com/"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrConfigFileMissing error = errors.New("The Auth config file is missing")
|
||||||
|
)
|
||||||
|
|
||||||
type AuthConfig struct {
|
type AuthConfig struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
@@ -75,7 +82,7 @@ func DecodeAuth(authStr string) (*AuthConfig, error) {
|
|||||||
func LoadConfig(rootPath string) (*AuthConfig, error) {
|
func LoadConfig(rootPath string) (*AuthConfig, error) {
|
||||||
confFile := path.Join(rootPath, CONFIGFILE)
|
confFile := path.Join(rootPath, CONFIGFILE)
|
||||||
if _, err := os.Stat(confFile); err != nil {
|
if _, err := os.Stat(confFile); err != nil {
|
||||||
return &AuthConfig{}, fmt.Errorf("The Auth config file is missing")
|
return nil, ErrConfigFileMissing
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadFile(confFile)
|
b, err := ioutil.ReadFile(confFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,7 +104,7 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save the auth config
|
// save the auth config
|
||||||
func saveConfig(rootPath, authStr string, email string) error {
|
func SaveConfig(rootPath, authStr string, email string) error {
|
||||||
confFile := path.Join(rootPath, CONFIGFILE)
|
confFile := path.Join(rootPath, CONFIGFILE)
|
||||||
if len(email) == 0 {
|
if len(email) == 0 {
|
||||||
os.Remove(confFile)
|
os.Remove(confFile)
|
||||||
@@ -161,7 +168,9 @@ func Login(authConfig *AuthConfig) (string, error) {
|
|||||||
status = "Login Succeeded\n"
|
status = "Login Succeeded\n"
|
||||||
storeConfig = true
|
storeConfig = true
|
||||||
} else if resp.StatusCode == 401 {
|
} else if resp.StatusCode == 401 {
|
||||||
saveConfig(authConfig.rootPath, "", "")
|
if err := SaveConfig(authConfig.rootPath, "", ""); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
return "", fmt.Errorf("Wrong login/password, please try again")
|
return "", fmt.Errorf("Wrong login/password, please try again")
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body,
|
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body,
|
||||||
@@ -175,7 +184,9 @@ func Login(authConfig *AuthConfig) (string, error) {
|
|||||||
}
|
}
|
||||||
if storeConfig {
|
if storeConfig {
|
||||||
authStr := EncodeAuth(authConfig)
|
authStr := EncodeAuth(authConfig)
|
||||||
saveConfig(authConfig.rootPath, authStr, authConfig.Email)
|
if err := SaveConfig(authConfig.rootPath, authStr, authConfig.Email); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-14
@@ -12,12 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BuilderClient interface {
|
|
||||||
Build(io.Reader) (string, error)
|
|
||||||
CmdFrom(string) error
|
|
||||||
CmdRun(string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type builderClient struct {
|
type builderClient struct {
|
||||||
cli *DockerCli
|
cli *DockerCli
|
||||||
|
|
||||||
@@ -158,8 +152,23 @@ func (b *builderClient) CmdExpose(args string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *builderClient) CmdInsert(args string) error {
|
func (b *builderClient) CmdInsert(args string) error {
|
||||||
// FIXME: Reimplement this once the remove_hijack branch gets merged.
|
// tmp := strings.SplitN(args, "\t ", 2)
|
||||||
// We need to retrieve the resulting Id
|
// sourceUrl, destPath := tmp[0], tmp[1]
|
||||||
|
|
||||||
|
// v := url.Values{}
|
||||||
|
// v.Set("url", sourceUrl)
|
||||||
|
// v.Set("path", destPath)
|
||||||
|
// body, _, err := b.cli.call("POST", "/images/insert?"+v.Encode(), nil)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// apiId := &ApiId{}
|
||||||
|
// if err := json.Unmarshal(body, apiId); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// FIXME: Reimplement this, we need to retrieve the resulting Id
|
||||||
return fmt.Errorf("INSERT not implemented")
|
return fmt.Errorf("INSERT not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +249,7 @@ func (b *builderClient) commit(id string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
|
func (b *builderClient) Build(dockerfile, context io.Reader) (string, error) {
|
||||||
defer b.clearTmp(b.tmpContainers, b.tmpImages)
|
defer b.clearTmp(b.tmpContainers, b.tmpImages)
|
||||||
file := bufio.NewReader(dockerfile)
|
file := bufio.NewReader(dockerfile)
|
||||||
for {
|
for {
|
||||||
@@ -263,18 +272,18 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
|
|||||||
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
||||||
arguments := strings.Trim(tmp[1], " ")
|
arguments := strings.Trim(tmp[1], " ")
|
||||||
|
|
||||||
fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
fmt.Fprintf(os.Stderr, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
||||||
|
|
||||||
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
||||||
if !exists {
|
if !exists {
|
||||||
fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction))
|
fmt.Fprintf(os.Stderr, "Skipping unknown instruction %s\n", strings.ToUpper(instruction))
|
||||||
}
|
}
|
||||||
ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
|
ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
|
||||||
if ret != nil {
|
if ret != nil {
|
||||||
return "", ret.(error)
|
return "", ret.(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("===> %v\n", b.image)
|
fmt.Fprintf(os.Stderr, "===> %v\n", b.image)
|
||||||
}
|
}
|
||||||
if b.needCommit {
|
if b.needCommit {
|
||||||
if err := b.commit(""); err != nil {
|
if err := b.commit(""); err != nil {
|
||||||
@@ -289,13 +298,13 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
|
|||||||
for i := range b.tmpContainers {
|
for i := range b.tmpContainers {
|
||||||
delete(b.tmpContainers, i)
|
delete(b.tmpContainers, i)
|
||||||
}
|
}
|
||||||
fmt.Printf("Build finished. image id: %s\n", b.image)
|
fmt.Fprintf(os.Stderr, "Build finished. image id: %s\n", b.image)
|
||||||
return b.image, nil
|
return b.image, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("An error occured during the build\n")
|
return "", fmt.Errorf("An error occured during the build\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuilderClient(addr string, port int) BuilderClient {
|
func NewBuilderClient(addr string, port int) BuildFile {
|
||||||
return &builderClient{
|
return &builderClient{
|
||||||
cli: NewDockerCli(addr, port),
|
cli: NewDockerCli(addr, port),
|
||||||
config: &Config{},
|
config: &Config{},
|
||||||
|
|||||||
+364
@@ -0,0 +1,364 @@
|
|||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BuildFile interface {
|
||||||
|
Build(io.Reader, io.Reader) (string, error)
|
||||||
|
CmdFrom(string) error
|
||||||
|
CmdRun(string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type buildFile struct {
|
||||||
|
runtime *Runtime
|
||||||
|
builder *Builder
|
||||||
|
srv *Server
|
||||||
|
|
||||||
|
image string
|
||||||
|
maintainer string
|
||||||
|
config *Config
|
||||||
|
context string
|
||||||
|
|
||||||
|
tmpContainers map[string]struct{}
|
||||||
|
tmpImages map[string]struct{}
|
||||||
|
|
||||||
|
out io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) clearTmp(containers, images map[string]struct{}) {
|
||||||
|
for c := range containers {
|
||||||
|
tmp := b.runtime.Get(c)
|
||||||
|
b.runtime.Destroy(tmp)
|
||||||
|
utils.Debugf("Removing container %s", c)
|
||||||
|
}
|
||||||
|
for i := range images {
|
||||||
|
b.runtime.graph.Delete(i)
|
||||||
|
utils.Debugf("Removing image %s", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdFrom(name string) error {
|
||||||
|
image, err := b.runtime.repositories.LookupImage(name)
|
||||||
|
if err != nil {
|
||||||
|
if b.runtime.graph.IsNotExist(err) {
|
||||||
|
|
||||||
|
var tag, remote string
|
||||||
|
if strings.Contains(name, ":") {
|
||||||
|
remoteParts := strings.Split(name, ":")
|
||||||
|
tag = remoteParts[1]
|
||||||
|
remote = remoteParts[0]
|
||||||
|
} else {
|
||||||
|
remote = name
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := b.srv.ImagePull(remote, tag, "", b.out, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
image, err = b.runtime.repositories.LookupImage(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.image = image.Id
|
||||||
|
b.config = &Config{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdMaintainer(name string) error {
|
||||||
|
b.maintainer = name
|
||||||
|
return b.commit("", b.config.Cmd, fmt.Sprintf("MAINTAINER %s", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdRun(args string) error {
|
||||||
|
if b.image == "" {
|
||||||
|
return fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
|
}
|
||||||
|
config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := b.config.Cmd
|
||||||
|
b.config.Cmd = nil
|
||||||
|
MergeConfig(b.config, config)
|
||||||
|
|
||||||
|
utils.Debugf("Command to be executed: %v", b.config.Cmd)
|
||||||
|
|
||||||
|
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||||
|
return err
|
||||||
|
} else if cache != nil {
|
||||||
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
|
b.image = cache.Id
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
utils.Debugf("[BUILDER] Cache miss")
|
||||||
|
}
|
||||||
|
|
||||||
|
cid, err := b.run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := b.commit(cid, cmd, "run"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.config.Cmd = cmd
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdEnv(args string) error {
|
||||||
|
tmp := strings.SplitN(args, " ", 2)
|
||||||
|
if len(tmp) != 2 {
|
||||||
|
return fmt.Errorf("Invalid ENV format")
|
||||||
|
}
|
||||||
|
key := strings.Trim(tmp[0], " ")
|
||||||
|
value := strings.Trim(tmp[1], " ")
|
||||||
|
|
||||||
|
for i, elem := range b.config.Env {
|
||||||
|
if strings.HasPrefix(elem, key+"=") {
|
||||||
|
b.config.Env[i] = key + "=" + value
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.config.Env = append(b.config.Env, key+"="+value)
|
||||||
|
return b.commit("", b.config.Cmd, fmt.Sprintf("ENV %s=%s", key, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdCmd(args string) error {
|
||||||
|
var cmd []string
|
||||||
|
if err := json.Unmarshal([]byte(args), &cmd); err != nil {
|
||||||
|
utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err)
|
||||||
|
cmd = []string{"/bin/sh", "-c", args}
|
||||||
|
}
|
||||||
|
if err := b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.config.Cmd = cmd
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdExpose(args string) error {
|
||||||
|
ports := strings.Split(args, " ")
|
||||||
|
b.config.PortSpecs = append(ports, b.config.PortSpecs...)
|
||||||
|
return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdInsert(args string) error {
|
||||||
|
return fmt.Errorf("INSERT has been deprecated. Please use ADD instead")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdCopy(args string) error {
|
||||||
|
return fmt.Errorf("COPY has been deprecated. Please use ADD instead")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdAdd(args string) error {
|
||||||
|
if b.context == "" {
|
||||||
|
return fmt.Errorf("No context given. Impossible to use ADD")
|
||||||
|
}
|
||||||
|
tmp := strings.SplitN(args, " ", 2)
|
||||||
|
if len(tmp) != 2 {
|
||||||
|
return fmt.Errorf("Invalid ADD format")
|
||||||
|
}
|
||||||
|
orig := strings.Trim(tmp[0], " ")
|
||||||
|
dest := strings.Trim(tmp[1], " ")
|
||||||
|
|
||||||
|
cmd := b.config.Cmd
|
||||||
|
b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) ADD %s in %s", orig, dest)}
|
||||||
|
cid, err := b.run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
container := b.runtime.Get(cid)
|
||||||
|
if container == nil {
|
||||||
|
return fmt.Errorf("Error while creating the container (CmdAdd)")
|
||||||
|
}
|
||||||
|
if err := container.EnsureMounted(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer container.Unmount()
|
||||||
|
|
||||||
|
origPath := path.Join(b.context, orig)
|
||||||
|
destPath := path.Join(container.RootfsPath(), dest)
|
||||||
|
|
||||||
|
fi, err := os.Stat(origPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if fi.IsDir() {
|
||||||
|
if err := os.MkdirAll(destPath, 0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(path.Join(b.context, orig))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, fi := range files {
|
||||||
|
if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := os.MkdirAll(path.Dir(destPath), 0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := utils.CopyDirectory(origPath, destPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := b.commit(cid, cmd, fmt.Sprintf("ADD %s in %s", orig, dest)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.config.Cmd = cmd
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) run() (string, error) {
|
||||||
|
if b.image == "" {
|
||||||
|
return "", fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
|
}
|
||||||
|
b.config.Image = b.image
|
||||||
|
|
||||||
|
// Create the container and start it
|
||||||
|
c, err := b.builder.Create(b.config)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
b.tmpContainers[c.Id] = struct{}{}
|
||||||
|
|
||||||
|
//start the container
|
||||||
|
if err := c.Start(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for it to finish
|
||||||
|
if ret := c.Wait(); ret != 0 {
|
||||||
|
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit the container <id> with the autorun command <autoCmd>
|
||||||
|
func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
||||||
|
if b.image == "" {
|
||||||
|
return fmt.Errorf("Please provide a source image with `from` prior to commit")
|
||||||
|
}
|
||||||
|
b.config.Image = b.image
|
||||||
|
if id == "" {
|
||||||
|
b.config.Cmd = []string{"/bin/sh", "-c", "#(nop) " + comment}
|
||||||
|
|
||||||
|
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||||
|
return err
|
||||||
|
} else if cache != nil {
|
||||||
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
|
b.image = cache.Id
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
utils.Debugf("[BUILDER] Cache miss")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cid, err := b.run(); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
id = cid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
container := b.runtime.Get(id)
|
||||||
|
if container == nil {
|
||||||
|
return fmt.Errorf("An error occured while creating the container")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Actually copy the struct
|
||||||
|
autoConfig := *b.config
|
||||||
|
autoConfig.Cmd = autoCmd
|
||||||
|
// Commit the container
|
||||||
|
image, err := b.builder.Commit(container, "", "", "", b.maintainer, &autoConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.tmpImages[image.Id] = struct{}{}
|
||||||
|
b.image = image.Id
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
||||||
|
if context != nil {
|
||||||
|
name, err := ioutil.TempDir("/tmp", "docker-build")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if err := Untar(context, name); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(name)
|
||||||
|
b.context = name
|
||||||
|
}
|
||||||
|
file := bufio.NewReader(dockerfile)
|
||||||
|
for {
|
||||||
|
line, err := file.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
line = strings.Replace(strings.TrimSpace(line), " ", " ", 1)
|
||||||
|
// Skip comments and empty line
|
||||||
|
if len(line) == 0 || line[0] == '#' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tmp := strings.SplitN(line, " ", 2)
|
||||||
|
if len(tmp) != 2 {
|
||||||
|
return "", fmt.Errorf("Invalid Dockerfile format")
|
||||||
|
}
|
||||||
|
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
||||||
|
arguments := strings.Trim(tmp[1], " ")
|
||||||
|
|
||||||
|
fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
||||||
|
|
||||||
|
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
||||||
|
if !exists {
|
||||||
|
fmt.Fprintf(b.out, "Skipping unknown instruction %s\n", strings.ToUpper(instruction))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
|
||||||
|
if ret != nil {
|
||||||
|
return "", ret.(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(b.out, "===> %v\n", b.image)
|
||||||
|
}
|
||||||
|
if b.image != "" {
|
||||||
|
fmt.Fprintf(b.out, "Build successful.\n===> %s\n", b.image)
|
||||||
|
return b.image, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("An error occured during the build\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBuildFile(srv *Server, out io.Writer) BuildFile {
|
||||||
|
return &buildFile{
|
||||||
|
builder: NewBuilder(srv.runtime),
|
||||||
|
runtime: srv.runtime,
|
||||||
|
srv: srv,
|
||||||
|
config: &Config{},
|
||||||
|
out: out,
|
||||||
|
tmpContainers: make(map[string]struct{}),
|
||||||
|
tmpImages: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Dockerfile = `
|
||||||
|
# VERSION 0.1
|
||||||
|
# DOCKER-VERSION 0.2
|
||||||
|
|
||||||
|
from ` + unitTestImageName + `
|
||||||
|
run sh -c 'echo root:testpass > /tmp/passwd'
|
||||||
|
run mkdir -p /var/run/sshd
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestBuild(t *testing.T) {
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
buildfile := NewBuildFile(srv, &utils.NopWriter{})
|
||||||
|
|
||||||
|
imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := NewBuilder(runtime)
|
||||||
|
container, err := builder.Create(
|
||||||
|
&Config{
|
||||||
|
Image: imgId,
|
||||||
|
Cmd: []string{"cat", "/tmp/passwd"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
|
output, err := container.Output()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if string(output) != "root:testpass\n" {
|
||||||
|
t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
container2, err := builder.Create(
|
||||||
|
&Config{
|
||||||
|
Image: imgId,
|
||||||
|
Cmd: []string{"ls", "-d", "/var/run/sshd"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer runtime.Destroy(container2)
|
||||||
|
|
||||||
|
output, err = container2.Output()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if string(output) != "/var/run/sshd\n" {
|
||||||
|
t.Fatal("/var/run/sshd has not been created")
|
||||||
|
}
|
||||||
|
}
|
||||||
+309
-117
@@ -10,35 +10,43 @@ import (
|
|||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"mime/multipart"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "0.3.3"
|
const VERSION = "0.3.4"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GIT_COMMIT string
|
GIT_COMMIT string
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseCommands(args ...string) error {
|
func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) {
|
||||||
cli := NewDockerCli("0.0.0.0", 4243)
|
methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:])
|
||||||
|
return reflect.TypeOf(cli).MethodByName(methodName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseCommands(addr string, port int, args ...string) error {
|
||||||
|
cli := NewDockerCli(addr, port)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:])
|
method, exists := cli.getMethod(args[0])
|
||||||
method, exists := reflect.TypeOf(cli).MethodByName(methodName)
|
|
||||||
if !exists {
|
if !exists {
|
||||||
fmt.Println("Error: Command not found:", args[0])
|
fmt.Println("Error: Command not found:", args[0])
|
||||||
return cli.CmdHelp(args...)
|
return cli.CmdHelp(args[1:]...)
|
||||||
}
|
}
|
||||||
ret := method.Func.CallSlice([]reflect.Value{
|
ret := method.Func.CallSlice([]reflect.Value{
|
||||||
reflect.ValueOf(cli),
|
reflect.ValueOf(cli),
|
||||||
@@ -53,38 +61,50 @@ func ParseCommands(args ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) CmdHelp(args ...string) error {
|
func (cli *DockerCli) CmdHelp(args ...string) error {
|
||||||
help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
|
if len(args) > 0 {
|
||||||
for cmd, description := range map[string]string{
|
method, exists := cli.getMethod(args[0])
|
||||||
"attach": "Attach to a running container",
|
if !exists {
|
||||||
"build": "Build a container from Dockerfile or via stdin",
|
fmt.Println("Error: Command not found:", args[0])
|
||||||
"commit": "Create a new image from a container's changes",
|
} else {
|
||||||
"diff": "Inspect changes on a container's filesystem",
|
method.Func.CallSlice([]reflect.Value{
|
||||||
"export": "Stream the contents of a container as a tar archive",
|
reflect.ValueOf(cli),
|
||||||
"history": "Show the history of an image",
|
reflect.ValueOf([]string{"--help"}),
|
||||||
"images": "List images",
|
})[0].Interface()
|
||||||
"import": "Create a new filesystem image from the contents of a tarball",
|
return nil
|
||||||
"info": "Display system-wide information",
|
}
|
||||||
"insert": "Insert a file in an image",
|
}
|
||||||
"inspect": "Return low-level information on a container",
|
help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.host, cli.port)
|
||||||
"kill": "Kill a running container",
|
for _, command := range [][2]string{
|
||||||
"login": "Register or Login to the docker registry server",
|
{"attach", "Attach to a running container"},
|
||||||
"logs": "Fetch the logs of a container",
|
{"build", "Build a container from a Dockerfile"},
|
||||||
"port": "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT",
|
{"commit", "Create a new image from a container's changes"},
|
||||||
"ps": "List containers",
|
{"diff", "Inspect changes on a container's filesystem"},
|
||||||
"pull": "Pull an image or a repository from the docker registry server",
|
{"export", "Stream the contents of a container as a tar archive"},
|
||||||
"push": "Push an image or a repository to the docker registry server",
|
{"history", "Show the history of an image"},
|
||||||
"restart": "Restart a running container",
|
{"images", "List images"},
|
||||||
"rm": "Remove a container",
|
{"import", "Create a new filesystem image from the contents of a tarball"},
|
||||||
"rmi": "Remove an image",
|
{"info", "Display system-wide information"},
|
||||||
"run": "Run a command in a new container",
|
{"insert", "Insert a file in an image"},
|
||||||
"search": "Search for an image in the docker index",
|
{"inspect", "Return low-level information on a container"},
|
||||||
"start": "Start a stopped container",
|
{"kill", "Kill a running container"},
|
||||||
"stop": "Stop a running container",
|
{"login", "Register or Login to the docker registry server"},
|
||||||
"tag": "Tag an image into a repository",
|
{"logs", "Fetch the logs of a container"},
|
||||||
"version": "Show the docker version information",
|
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
|
||||||
"wait": "Block until a container stops, then print its exit code",
|
{"ps", "List containers"},
|
||||||
|
{"pull", "Pull an image or a repository from the docker registry server"},
|
||||||
|
{"push", "Push an image or a repository to the docker registry server"},
|
||||||
|
{"restart", "Restart a running container"},
|
||||||
|
{"rm", "Remove a container"},
|
||||||
|
{"rmi", "Remove an image"},
|
||||||
|
{"run", "Run a command in a new container"},
|
||||||
|
{"search", "Search for an image in the docker index"},
|
||||||
|
{"start", "Start a stopped container"},
|
||||||
|
{"stop", "Stop a running container"},
|
||||||
|
{"tag", "Tag an image into a repository"},
|
||||||
|
{"version", "Show the docker version information"},
|
||||||
|
{"wait", "Block until a container stops}, then print its exit code"},
|
||||||
} {
|
} {
|
||||||
help += fmt.Sprintf(" %-10.10s%s\n", cmd, description)
|
help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1])
|
||||||
}
|
}
|
||||||
fmt.Println(help)
|
fmt.Println(help)
|
||||||
return nil
|
return nil
|
||||||
@@ -104,39 +124,107 @@ func (cli *DockerCli) CmdInsert(args ...string) error {
|
|||||||
v.Set("url", cmd.Arg(1))
|
v.Set("url", cmd.Arg(1))
|
||||||
v.Set("path", cmd.Arg(2))
|
v.Set("path", cmd.Arg(2))
|
||||||
|
|
||||||
err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout)
|
if err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) CmdBuild(args ...string) error {
|
func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin")
|
cmd := Subcmd("build", "[OPTIONS] PATH | -", "Build a new container image from the source code at PATH")
|
||||||
|
tag := cmd.String("t", "", "Tag to be applied to the resulting image in case of success")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if cmd.NArg() != 1 {
|
||||||
|
cmd.Usage()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file io.ReadCloser
|
multipartBody io.Reader
|
||||||
err error
|
file io.ReadCloser
|
||||||
|
contextPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
if cmd.NArg() == 0 {
|
// Init the needed component for the Multipart
|
||||||
file, err = os.Open("Dockerfile")
|
buff := bytes.NewBuffer([]byte{})
|
||||||
if err != nil {
|
multipartBody = buff
|
||||||
return err
|
w := multipart.NewWriter(buff)
|
||||||
}
|
boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n")
|
||||||
} else if cmd.Arg(0) == "-" {
|
|
||||||
|
compression := Bzip2
|
||||||
|
|
||||||
|
if cmd.Arg(0) == "-" {
|
||||||
file = os.Stdin
|
file = os.Stdin
|
||||||
} else {
|
} else {
|
||||||
file, err = os.Open(cmd.Arg(0))
|
// Send Dockerfile from arg/Dockerfile (deprecate later)
|
||||||
|
if f, err := os.Open(path.Join(cmd.Arg(0), "Dockerfile")); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
file = f
|
||||||
|
}
|
||||||
|
// Send context from arg
|
||||||
|
// Create a FormFile multipart for the context if needed
|
||||||
|
// FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage?
|
||||||
|
context, err := Tar(cmd.Arg(0), compression)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// NOTE: Do this in case '.' or '..' is input
|
||||||
|
absPath, err := filepath.Abs(cmd.Arg(0))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension()); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
// FIXME: Find a way to have a progressbar for the upload too
|
||||||
|
io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Caching Context %v/%v (%v)\r", false))
|
||||||
|
}
|
||||||
|
multipartBody = io.MultiReader(multipartBody, boundary)
|
||||||
}
|
}
|
||||||
if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file); err != nil {
|
// Create a FormFile multipart for the Dockerfile
|
||||||
|
if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
io.Copy(wField, file)
|
||||||
|
}
|
||||||
|
multipartBody = io.MultiReader(multipartBody, boundary)
|
||||||
|
|
||||||
|
v := &url.Values{}
|
||||||
|
v.Set("t", *tag)
|
||||||
|
// Send the multipart request with correct content-type
|
||||||
|
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s?%s", cli.host, cli.port, "/build", v.Encode()), multipartBody)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||||
|
if contextPath != "" {
|
||||||
|
req.Header.Set("X-Docker-Context-Compression", compression.Flag())
|
||||||
|
fmt.Println("Uploading Context...")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error: %s", body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output the result
|
||||||
|
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,12 +371,10 @@ func (cli *DockerCli) CmdWait(args ...string) error {
|
|||||||
// 'docker version': show version information
|
// 'docker version': show version information
|
||||||
func (cli *DockerCli) CmdVersion(args ...string) error {
|
func (cli *DockerCli) CmdVersion(args ...string) error {
|
||||||
cmd := Subcmd("version", "", "Show the docker version information.")
|
cmd := Subcmd("version", "", "Show the docker version information.")
|
||||||
fmt.Println(len(args))
|
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(cmd.NArg())
|
|
||||||
if cmd.NArg() > 0 {
|
if cmd.NArg() > 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return nil
|
return nil
|
||||||
@@ -607,39 +693,13 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _, err := cli.call("GET", "/auth", nil)
|
username, err := cli.checkIfLogged(*registry == "", "push")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var out auth.AuthConfig
|
|
||||||
err = json.Unmarshal(body, &out)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the login failed AND we're using the index, abort
|
|
||||||
if *registry == "" && out.Username == "" {
|
|
||||||
if err := cli.CmdLogin(args...); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
body, _, err = cli.call("GET", "/auth", nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(body, &out)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if out.Username == "" {
|
|
||||||
return fmt.Errorf("Please login prior to push. ('docker login')")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(strings.SplitN(name, "/", 2)) == 1 {
|
if len(strings.SplitN(name, "/", 2)) == 1 {
|
||||||
return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)", out.Username, name)
|
return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)", username, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
@@ -670,6 +730,12 @@ func (cli *DockerCli) CmdPull(args ...string) error {
|
|||||||
remote = remoteParts[0]
|
remote = remoteParts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(remote, "/") {
|
||||||
|
if _, err := cli.checkIfLogged(true, "pull"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("fromImage", remote)
|
v.Set("fromImage", remote)
|
||||||
v.Set("tag", *tag)
|
v.Set("tag", *tag)
|
||||||
@@ -790,7 +856,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||||||
v.Set("before", *before)
|
v.Set("before", *before)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _, err := cli.call("GET", "/containers/ps?"+v.Encode(), nil)
|
body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -808,9 +874,9 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
@@ -927,7 +993,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
|
|||||||
v.Set("stdout", "1")
|
v.Set("stdout", "1")
|
||||||
v.Set("stderr", "1")
|
v.Set("stderr", "1")
|
||||||
|
|
||||||
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false); err != nil {
|
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false, nil, os.Stdout); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -954,14 +1020,35 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
splitStderr := container.Config.Tty
|
||||||
|
|
||||||
|
connections := 1
|
||||||
|
if splitStderr {
|
||||||
|
connections += 1
|
||||||
|
}
|
||||||
|
chErrors := make(chan error, connections)
|
||||||
|
cli.monitorTtySize(cmd.Arg(0))
|
||||||
|
if splitStderr {
|
||||||
|
go func() {
|
||||||
|
chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr)
|
||||||
|
}()
|
||||||
|
}
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("stream", "1")
|
v.Set("stream", "1")
|
||||||
v.Set("stdout", "1")
|
|
||||||
v.Set("stderr", "1")
|
|
||||||
v.Set("stdin", "1")
|
v.Set("stdin", "1")
|
||||||
|
v.Set("stdout", "1")
|
||||||
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty); err != nil {
|
if !splitStderr {
|
||||||
return err
|
v.Set("stderr", "1")
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout)
|
||||||
|
}()
|
||||||
|
for connections > 0 {
|
||||||
|
err := <-chErrors
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
connections -= 1
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1125,19 +1212,14 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||||||
fmt.Fprintln(os.Stderr, "WARNING: ", warning)
|
fmt.Fprintln(os.Stderr, "WARNING: ", warning)
|
||||||
}
|
}
|
||||||
|
|
||||||
v := url.Values{}
|
splitStderr := !config.Tty
|
||||||
v.Set("logs", "1")
|
|
||||||
v.Set("stream", "1")
|
|
||||||
|
|
||||||
if config.AttachStdin {
|
connections := 0
|
||||||
v.Set("stdin", "1")
|
if config.AttachStdin || config.AttachStdout || (!splitStderr && config.AttachStderr) {
|
||||||
|
connections += 1
|
||||||
}
|
}
|
||||||
if config.AttachStdout {
|
if splitStderr && config.AttachStderr {
|
||||||
v.Set("stdout", "1")
|
connections += 1
|
||||||
}
|
|
||||||
if config.AttachStderr {
|
|
||||||
v.Set("stderr", "1")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
@@ -1146,9 +1228,38 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.AttachStdin || config.AttachStdout || config.AttachStderr {
|
if connections > 0 {
|
||||||
if err := cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil {
|
chErrors := make(chan error, connections)
|
||||||
return err
|
cli.monitorTtySize(out.Id)
|
||||||
|
|
||||||
|
if splitStderr && config.AttachStderr {
|
||||||
|
go func() {
|
||||||
|
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
v := url.Values{}
|
||||||
|
v.Set("logs", "1")
|
||||||
|
v.Set("stream", "1")
|
||||||
|
|
||||||
|
if config.AttachStdin {
|
||||||
|
v.Set("stdin", "1")
|
||||||
|
}
|
||||||
|
if config.AttachStdout {
|
||||||
|
v.Set("stdout", "1")
|
||||||
|
}
|
||||||
|
if !splitStderr && config.AttachStderr {
|
||||||
|
v.Set("stderr", "1")
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
||||||
|
}()
|
||||||
|
for connections > 0 {
|
||||||
|
err := <-chErrors
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
connections -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !config.AttachStdout && !config.AttachStderr {
|
if !config.AttachStdout && !config.AttachStderr {
|
||||||
@@ -1157,6 +1268,40 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) checkIfLogged(condition bool, action string) (string, error) {
|
||||||
|
body, _, err := cli.call("GET", "/auth", nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var out auth.AuthConfig
|
||||||
|
err = json.Unmarshal(body, &out)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If condition AND the login failed
|
||||||
|
if condition && out.Username == "" {
|
||||||
|
if err := cli.CmdLogin(""); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, _, err = cli.call("GET", "/auth", nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(body, &out)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if out.Username == "" {
|
||||||
|
return "", fmt.Errorf("Please login prior to %s. ('docker login')", action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.Username, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, error) {
|
func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, error) {
|
||||||
var params io.Reader
|
var params io.Reader
|
||||||
if data != nil {
|
if data != nil {
|
||||||
@@ -1167,7 +1312,7 @@ func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int,
|
|||||||
params = bytes.NewBuffer(buf)
|
params = bytes.NewBuffer(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%f", cli.host, cli.port, API_VERSION)+path, params)
|
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
@@ -1199,7 +1344,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
|||||||
if (method == "POST" || method == "PUT") && in == nil {
|
if (method == "POST" || method == "PUT") && in == nil {
|
||||||
in = bytes.NewReader([]byte{})
|
in = bytes.NewReader([]byte{})
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%f%s", cli.host, cli.port, API_VERSION, path), in)
|
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1223,14 +1368,35 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
|||||||
return fmt.Errorf("error: %s", body)
|
return fmt.Errorf("error: %s", body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
if resp.Header.Get("Content-Type") == "application/json" {
|
||||||
return err
|
type Message struct {
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
Progress string `json:"progress,omitempty"`
|
||||||
|
}
|
||||||
|
dec := json.NewDecoder(resp.Body)
|
||||||
|
for {
|
||||||
|
var m Message
|
||||||
|
if err := dec.Decode(&m); err == io.EOF {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if m.Progress != "" {
|
||||||
|
fmt.Fprintf(out, "Downloading %s\r", m.Progress)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(out, "%s\n", m.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error {
|
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error {
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("/v%f%s", API_VERSION, path), nil)
|
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", API_VERSION, path), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1247,20 +1413,19 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error {
|
|||||||
defer rwc.Close()
|
defer rwc.Close()
|
||||||
|
|
||||||
receiveStdout := utils.Go(func() error {
|
receiveStdout := utils.Go(func() error {
|
||||||
_, err := io.Copy(os.Stdout, br)
|
_, err := io.Copy(out, br)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
if setRawTerminal && term.IsTerminal(int(os.Stdin.Fd())) && os.Getenv("NORAW") == "" {
|
if in != nil && setRawTerminal && term.IsTerminal(int(in.Fd())) && os.Getenv("NORAW") == "" {
|
||||||
if oldState, err := term.SetRawTerminal(); err != nil {
|
if oldState, err := term.SetRawTerminal(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
defer term.RestoreTerminal(oldState)
|
defer term.RestoreTerminal(oldState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendStdin := utils.Go(func() error {
|
sendStdin := utils.Go(func() error {
|
||||||
_, err := io.Copy(rwc, os.Stdin)
|
_, err := io.Copy(rwc, in)
|
||||||
if err := rwc.(*net.TCPConn).CloseWrite(); err != nil {
|
if err := rwc.(*net.TCPConn).CloseWrite(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err)
|
fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err)
|
||||||
}
|
}
|
||||||
@@ -1280,6 +1445,33 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) resizeTty(id string) {
|
||||||
|
ws, err := term.GetWinsize(os.Stdin.Fd())
|
||||||
|
if err != nil {
|
||||||
|
utils.Debugf("Error getting size: %s", err)
|
||||||
|
}
|
||||||
|
v := url.Values{}
|
||||||
|
v.Set("h", strconv.Itoa(int(ws.Height)))
|
||||||
|
v.Set("w", strconv.Itoa(int(ws.Width)))
|
||||||
|
if _, _, err := cli.call("POST", "/containers/"+id+"/resize?"+v.Encode(), nil); err != nil {
|
||||||
|
utils.Debugf("Error resize: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) monitorTtySize(id string) {
|
||||||
|
cli.resizeTty(id)
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, syscall.SIGWINCH)
|
||||||
|
go func() {
|
||||||
|
for sig := range c {
|
||||||
|
if sig == syscall.SIGWINCH {
|
||||||
|
cli.resizeTty(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func Subcmd(name, signature, description string) *flag.FlagSet {
|
func Subcmd(name, signature, description string) *flag.FlagSet {
|
||||||
flags := flag.NewFlagSet(name, flag.ContinueOnError)
|
flags := flag.NewFlagSet(name, flag.ContinueOnError)
|
||||||
flags.Usage = func() {
|
flags.Usage = func() {
|
||||||
@@ -1289,11 +1481,11 @@ func Subcmd(name, signature, description string) *flag.FlagSet {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDockerCli(host string, port int) *DockerCli {
|
func NewDockerCli(addr string, port int) *DockerCli {
|
||||||
return &DockerCli{host, port}
|
return &DockerCli{addr, port}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DockerCli struct {
|
type DockerCli struct {
|
||||||
host string
|
host string
|
||||||
port int
|
port int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/term"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"github.com/kr/pty"
|
"github.com/kr/pty"
|
||||||
"io"
|
"io"
|
||||||
@@ -754,6 +755,14 @@ func (container *Container) Wait() int {
|
|||||||
return container.State.ExitCode
|
return container.State.ExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) Resize(h, w int) error {
|
||||||
|
pty, ok := container.ptyMaster.(*os.File)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("ptyMaster does not have Fd() method")
|
||||||
|
}
|
||||||
|
return term.SetWinsize(pty.Fd(), &term.Winsize{Height: uint16(h), Width: uint16(w)})
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) ExportRw() (Archive, error) {
|
func (container *Container) ExportRw() (Archive, error) {
|
||||||
return Tar(container.rwPath(), Uncompressed)
|
return Tar(container.rwPath(), Uncompressed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
# Maintainer wanted! Enroll on #docker@freenode
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Solomon Hykes <solomon@dotcloud.com>
|
||||||
+28
-4
@@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,18 +24,38 @@ func main() {
|
|||||||
docker.SysInit()
|
docker.SysInit()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
host := "127.0.0.1"
|
||||||
|
port := 4243
|
||||||
// FIXME: Switch d and D ? (to be more sshd like)
|
// FIXME: Switch d and D ? (to be more sshd like)
|
||||||
flDaemon := flag.Bool("d", false, "Daemon mode")
|
flDaemon := flag.Bool("d", false, "Daemon mode")
|
||||||
flDebug := flag.Bool("D", false, "Debug mode")
|
flDebug := flag.Bool("D", false, "Debug mode")
|
||||||
flAutoRestart := flag.Bool("r", false, "Restart previously running containers")
|
flAutoRestart := flag.Bool("r", false, "Restart previously running containers")
|
||||||
bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge")
|
bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge")
|
||||||
pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID")
|
pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID")
|
||||||
|
flHost := flag.String("H", fmt.Sprintf("%s:%d", host, port), "Host:port to bind/connect to")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *bridgeName != "" {
|
if *bridgeName != "" {
|
||||||
docker.NetworkBridgeIface = *bridgeName
|
docker.NetworkBridgeIface = *bridgeName
|
||||||
} else {
|
} else {
|
||||||
docker.NetworkBridgeIface = docker.DefaultNetworkBridge
|
docker.NetworkBridgeIface = docker.DefaultNetworkBridge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(*flHost, ":") {
|
||||||
|
hostParts := strings.Split(*flHost, ":")
|
||||||
|
if len(hostParts) != 2 {
|
||||||
|
log.Fatal("Invalid bind address format.")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
if hostParts[0] != "" {
|
||||||
|
host = hostParts[0]
|
||||||
|
}
|
||||||
|
if p, err := strconv.Atoi(hostParts[1]); err == nil {
|
||||||
|
port = p
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
host = *flHost
|
||||||
|
}
|
||||||
|
|
||||||
if *flDebug {
|
if *flDebug {
|
||||||
os.Setenv("DEBUG", "1")
|
os.Setenv("DEBUG", "1")
|
||||||
}
|
}
|
||||||
@@ -44,12 +65,12 @@ func main() {
|
|||||||
flag.Usage()
|
flag.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := daemon(*pidfile, *flAutoRestart); err != nil {
|
if err := daemon(*pidfile, host, port, *flAutoRestart); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := docker.ParseCommands(flag.Args()...); err != nil {
|
if err := docker.ParseCommands(host, port, flag.Args()...); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
@@ -83,7 +104,10 @@ func removePidFile(pidfile string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func daemon(pidfile string, autoRestart bool) error {
|
func daemon(pidfile, addr string, port int, autoRestart bool) error {
|
||||||
|
if addr != "127.0.0.1" {
|
||||||
|
log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
|
||||||
|
}
|
||||||
if err := createPidFile(pidfile); err != nil {
|
if err := createPidFile(pidfile); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -103,5 +127,5 @@ func daemon(pidfile string, autoRestart bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return docker.ListenAndServe("0.0.0.0:4243", server, true)
|
return docker.ListenAndServe(fmt.Sprintf("%s:%d", addr, port), server, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Andy Rothfusz <andy@dotcloud.com>
|
||||||
|
Ken Cochrane <ken@dotcloud.com>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Solomon Hykes <solomon@dotcloud.com>
|
||||||
@@ -24,7 +24,7 @@ Docker Remote API
|
|||||||
List containers
|
List containers
|
||||||
***************
|
***************
|
||||||
|
|
||||||
.. http:get:: /containers/ps
|
.. http:get:: /containers/json
|
||||||
|
|
||||||
List containers
|
List containers
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ List containers
|
|||||||
|
|
||||||
.. sourcecode:: http
|
.. sourcecode:: http
|
||||||
|
|
||||||
GET /containers/ps?all=1&before=8dfafdbc3a40 HTTP/1.1
|
GET /containers/json?all=1&before=8dfafdbc3a40 HTTP/1.1
|
||||||
|
|
||||||
**Example response**:
|
**Example response**:
|
||||||
|
|
||||||
@@ -378,7 +378,7 @@ Attach to a container
|
|||||||
|
|
||||||
.. http:post:: /containers/(id)/attach
|
.. http:post:: /containers/(id)/attach
|
||||||
|
|
||||||
Stop the container ``id``
|
Attach to the container ``id``
|
||||||
|
|
||||||
**Example request**:
|
**Example request**:
|
||||||
|
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ POST /v1/users
|
|||||||
{"email": "sam@dotcloud.com", "password": "toto42", "username": "foobar"'}
|
{"email": "sam@dotcloud.com", "password": "toto42", "username": "foobar"'}
|
||||||
|
|
||||||
**Validation**:
|
**Validation**:
|
||||||
- **username** : min 4 character, max 30 characters, all lowercase no special characters.
|
- **username** : min 4 character, max 30 characters, must match the regular expression [a-z0-9_].
|
||||||
- **password**: min 5 characters
|
- **password**: min 5 characters
|
||||||
|
|
||||||
**Valid**: return HTTP 200
|
**Valid**: return HTTP 200
|
||||||
@@ -345,6 +345,11 @@ GET /v1/users
|
|||||||
|
|
||||||
The Registry does not know anything about users. Even though repositories are under usernames, it’s just a namespace for the registry. Allowing us to implement organizations or different namespaces per user later, without modifying the Registry’s API.
|
The Registry does not know anything about users. Even though repositories are under usernames, it’s just a namespace for the registry. Allowing us to implement organizations or different namespaces per user later, without modifying the Registry’s API.
|
||||||
|
|
||||||
|
The following naming restrictions apply:
|
||||||
|
|
||||||
|
- Namespaces must match the same regular expression as usernames (See 4.2.1.)
|
||||||
|
- Repository names must match the regular expression [a-zA-Z0-9-_.]
|
||||||
|
|
||||||
4.3.1 Get all tags
|
4.3.1 Get all tags
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ To list available commands, either run ``docker`` with no parameters or execute
|
|||||||
``docker help``::
|
``docker help``::
|
||||||
|
|
||||||
$ docker
|
$ docker
|
||||||
Usage: docker COMMAND [arg...]
|
Usage: docker [OPTIONS] COMMAND [arg...]
|
||||||
|
-H="127.0.0.1:4243": Host:port to bind/connect to
|
||||||
|
|
||||||
A self-sufficient runtime for linux containers.
|
A self-sufficient runtime for linux containers.
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,27 @@
|
|||||||
:description: Build a new image from the Dockerfile passed via stdin
|
:description: Build a new image from the Dockerfile passed via stdin
|
||||||
:keywords: build, docker, container, documentation
|
:keywords: build, docker, container, documentation
|
||||||
|
|
||||||
========================================================
|
================================================
|
||||||
``build`` -- Build a container from Dockerfile via stdin
|
``build`` -- Build a container from a Dockerfile
|
||||||
========================================================
|
================================================
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
Usage: docker build -
|
Usage: docker build [OPTIONS] PATH | -
|
||||||
Example: cat Dockerfile | docker build -
|
Build a new container image from the source code at PATH
|
||||||
Build a new image from the Dockerfile passed via stdin
|
-t="": Tag to be applied to the resulting image in case of success.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
docker build .
|
||||||
|
|
||||||
|
This will take the local Dockerfile
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
docker build -
|
||||||
|
|
||||||
|
This will read a Dockerfile form Stdin without context
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
:title: Building Blocks
|
|
||||||
:description: An introduction to docker and standard containers?
|
|
||||||
:keywords: containers, lxc, concepts, explanation
|
|
||||||
|
|
||||||
|
|
||||||
Building blocks
|
|
||||||
===============
|
|
||||||
|
|
||||||
.. _images:
|
|
||||||
|
|
||||||
Images
|
|
||||||
------
|
|
||||||
An original container image. These are stored on disk and are comparable with what you normally expect from a stopped virtual machine image. Images are stored (and retrieved from) repository
|
|
||||||
|
|
||||||
Images are stored on your local file system under /var/lib/docker/graph
|
|
||||||
|
|
||||||
|
|
||||||
.. _containers:
|
|
||||||
|
|
||||||
Containers
|
|
||||||
----------
|
|
||||||
A container is a local version of an image. It can be running or stopped, The equivalent would be a virtual machine instance.
|
|
||||||
|
|
||||||
Containers are stored on your local file system under /var/lib/docker/containers
|
|
||||||
|
|
||||||
@@ -13,5 +13,4 @@ Contents:
|
|||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
../index
|
../index
|
||||||
buildingblocks
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,101 +5,5 @@
|
|||||||
Contributing to Docker
|
Contributing to Docker
|
||||||
======================
|
======================
|
||||||
|
|
||||||
Want to hack on Docker? Awesome! There are instructions to get you
|
Want to hack on Docker? Awesome! The repository includes `all the instructions you need to get started <https://github.com/dotcloud/docker/blob/master/CONTRIBUTING.md>`.
|
||||||
started on the website: http://docker.io/gettingstarted.html
|
|
||||||
|
|
||||||
They are probably not perfect, please let us know if anything feels
|
|
||||||
wrong or incomplete.
|
|
||||||
|
|
||||||
Contribution guidelines
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
Pull requests are always welcome
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
We are always thrilled to receive pull requests, and do our best to
|
|
||||||
process them as fast as possible. Not sure if that typo is worth a pull
|
|
||||||
request? Do it! We will appreciate it.
|
|
||||||
|
|
||||||
If your pull request is not accepted on the first try, don't be
|
|
||||||
discouraged! If there's a problem with the implementation, hopefully you
|
|
||||||
received feedback on what to improve.
|
|
||||||
|
|
||||||
We're trying very hard to keep Docker lean and focused. We don't want it
|
|
||||||
to do everything for everybody. This means that we might decide against
|
|
||||||
incorporating a new feature. However, there might be a way to implement
|
|
||||||
that feature *on top of* docker.
|
|
||||||
|
|
||||||
Discuss your design on the mailing list
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
We recommend discussing your plans `on the mailing
|
|
||||||
list <https://groups.google.com/forum/?fromgroups#!forum/docker-club>`__
|
|
||||||
before starting to code - especially for more ambitious contributions.
|
|
||||||
This gives other contributors a chance to point you in the right
|
|
||||||
direction, give feedback on your design, and maybe point out if someone
|
|
||||||
else is working on the same thing.
|
|
||||||
|
|
||||||
Create issues...
|
|
||||||
~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Any significant improvement should be documented as `a github
|
|
||||||
issue <https://github.com/dotcloud/docker/issues>`__ before anybody
|
|
||||||
starts working on it.
|
|
||||||
|
|
||||||
...but check for existing issues first!
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Please take a moment to check that an issue doesn't already exist
|
|
||||||
documenting your bug report or improvement proposal. If it does, it
|
|
||||||
never hurts to add a quick "+1" or "I have this problem too". This will
|
|
||||||
help prioritize the most common problems and requests.
|
|
||||||
|
|
||||||
Conventions
|
|
||||||
~~~~~~~~~~~
|
|
||||||
|
|
||||||
Fork the repo and make changes on your fork in a feature branch:
|
|
||||||
|
|
||||||
- If it's a bugfix branch, name it XXX-something where XXX is the number of the
|
|
||||||
issue
|
|
||||||
- If it's a feature branch, create an enhancement issue to announce your
|
|
||||||
intentions, and name it XXX-something where XXX is the number of the issue.
|
|
||||||
|
|
||||||
Submit unit tests for your changes. Go has a great test framework built in; use
|
|
||||||
it! Take a look at existing tests for inspiration. Run the full test suite on
|
|
||||||
your branch before submitting a pull request.
|
|
||||||
|
|
||||||
Make sure you include relevant updates or additions to documentation when
|
|
||||||
creating or modifying features.
|
|
||||||
|
|
||||||
Write clean code. Universally formatted code promotes ease of writing, reading,
|
|
||||||
and maintenance. Always run ``go fmt`` before committing your changes. Most
|
|
||||||
editors have plugins that do this automatically, and there's also a git
|
|
||||||
pre-commit hook:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
|
|
||||||
|
|
||||||
|
|
||||||
Pull requests descriptions should be as clear as possible and include a
|
|
||||||
reference to all the issues that they address.
|
|
||||||
|
|
||||||
Code review comments may be added to your pull request. Discuss, then make the
|
|
||||||
suggested modifications and push additional commits to your feature branch. Be
|
|
||||||
sure to post a comment after pushing. The new commits will show up in the pull
|
|
||||||
request automatically, but the reviewers will not be notified unless you
|
|
||||||
comment.
|
|
||||||
|
|
||||||
Before the pull request is merged, make sure that you squash your commits into
|
|
||||||
logical units of work using ``git rebase -i`` and ``git push -f``. After every
|
|
||||||
commit the test suite should be passing. Include documentation changes in the
|
|
||||||
same commit so that a revert would remove all traces of the feature or fix.
|
|
||||||
|
|
||||||
Commits that fix or close an issue should include a reference like ``Closes #XXX``
|
|
||||||
or ``Fixes #XXX``, which will automatically close the issue when merged.
|
|
||||||
|
|
||||||
Add your name to the AUTHORS file, but make sure the list is sorted and your
|
|
||||||
name and email address match your git configuration. The AUTHORS file is
|
|
||||||
regenerated occasionally from the git commit history, so a mismatch may result
|
|
||||||
in your changes being overwritten.
|
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ lookup the public-facing port which is NAT-ed store the private port used by the
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
curl http://`hostname`:$WEB_PORT
|
# install curl if necessary, then ...
|
||||||
|
curl http://127.0.0.1:$WEB_PORT
|
||||||
Hello world!
|
Hello world!
|
||||||
|
|
||||||
access the web app using curl. If everything worked as planned you should see the line "Hello world!" inside of your console.
|
access the web app using curl. If everything worked as planned you should see the line "Hello world!" inside of your console.
|
||||||
|
|||||||
@@ -67,3 +67,21 @@ To start on system boot:
|
|||||||
::
|
::
|
||||||
|
|
||||||
sudo systemctl enable docker
|
sudo systemctl enable docker
|
||||||
|
|
||||||
|
Network Configuration
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
IPv4 packet forwarding is disabled by default on Arch, so internet access from inside
|
||||||
|
the container may not work.
|
||||||
|
|
||||||
|
To enable the forwarding, run as root on the host system:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
sysctl net.ipv4.ip_forward=1
|
||||||
|
|
||||||
|
And, to make it persistent across reboots, enable it on the host's **/etc/sysctl.conf**:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
net.ipv4.ip_forward=1
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ But we know people have had success running it under
|
|||||||
Dependencies:
|
Dependencies:
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
* 3.8 Kernel
|
* 3.8 Kernel (read more about :ref:`kernel`)
|
||||||
* AUFS filesystem support
|
* AUFS filesystem support
|
||||||
* lxc
|
* lxc
|
||||||
* bsdtar
|
* bsdtar
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Right now, the officially supported distribution are:
|
|||||||
|
|
||||||
Docker has the following dependencies
|
Docker has the following dependencies
|
||||||
|
|
||||||
* Linux kernel 3.8
|
* Linux kernel 3.8 (read more about :ref:`kernel`)
|
||||||
* AUFS file system support (we are working on BTRFS support as an alternative)
|
* AUFS file system support (we are working on BTRFS support as an alternative)
|
||||||
|
|
||||||
.. _ubuntu_precise:
|
.. _ubuntu_precise:
|
||||||
@@ -38,7 +38,7 @@ Due to a bug in LXC docker works best on the 3.8 kernel. Precise comes with a 3.
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
# install the backported kernel
|
# install the backported kernel
|
||||||
sudo apt-get update && sudo apt-get install linux-image-3.8.0-19-generic
|
sudo apt-get update && sudo apt-get install linux-image-generic-lts-raring
|
||||||
|
|
||||||
# reboot
|
# reboot
|
||||||
sudo reboot
|
sudo reboot
|
||||||
@@ -54,9 +54,9 @@ which makes installing Docker on Ubuntu very easy.
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
# Add the PPA sources to your apt sources list.
|
# Add the PPA sources to your apt sources list.
|
||||||
sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' > /etc/apt/sources.list.d/lxc-docker.list"
|
sudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud/lxc-docker
|
||||||
|
|
||||||
# Update your sources, you will see a warning.
|
# Update your sources
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
||||||
# Install, you will see another warning that the package cannot be authenticated. Confirm install.
|
# Install, you will see another warning that the package cannot be authenticated. Confirm install.
|
||||||
|
|||||||
@@ -33,6 +33,19 @@ Running an interactive shell
|
|||||||
# allocate a tty, attach stdin and stdout
|
# allocate a tty, attach stdin and stdout
|
||||||
docker run -i -t base /bin/bash
|
docker run -i -t base /bin/bash
|
||||||
|
|
||||||
|
Bind Docker to another host/port
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
If you want Docker to listen to another port and bind to another ip
|
||||||
|
use -host and -port on both deamon and client
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
# Run docker in daemon mode
|
||||||
|
sudo <path to>/docker -H 0.0.0.0:5555 &
|
||||||
|
# Download a base image
|
||||||
|
docker -H :5555 pull base
|
||||||
|
|
||||||
|
|
||||||
Starting a long-running worker process
|
Starting a long-running worker process
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|||||||
@@ -125,8 +125,14 @@ curl was installed within the image.
|
|||||||
.. note::
|
.. note::
|
||||||
The path must include the file name.
|
The path must include the file name.
|
||||||
|
|
||||||
.. note::
|
2.8 ADD
|
||||||
This instruction has temporarily disabled
|
-------
|
||||||
|
|
||||||
|
``ADD <src> <dest>``
|
||||||
|
|
||||||
|
The `ADD` instruction will insert the files from the `<src>` path of the context into `<dest>` path
|
||||||
|
of the container.
|
||||||
|
The context must be set in order to use this instruction. (see examples)
|
||||||
|
|
||||||
3. Dockerfile Examples
|
3. Dockerfile Examples
|
||||||
======================
|
======================
|
||||||
|
|||||||
+32
-32
@@ -25,9 +25,9 @@ Installation
|
|||||||
The module is available on the `Puppet Forge <https://forge.puppetlabs.com/garethr/docker/>`_
|
The module is available on the `Puppet Forge <https://forge.puppetlabs.com/garethr/docker/>`_
|
||||||
and can be installed using the built-in module tool.
|
and can be installed using the built-in module tool.
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
puppet module install garethr/docker
|
puppet module install garethr/docker
|
||||||
|
|
||||||
It can also be found on `GitHub <https://www.github.com/garethr/garethr-docker>`_
|
It can also be found on `GitHub <https://www.github.com/garethr/garethr-docker>`_
|
||||||
if you would rather download the source.
|
if you would rather download the source.
|
||||||
@@ -41,9 +41,9 @@ for managing images and containers.
|
|||||||
Installation
|
Installation
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
.. code-block:: ruby
|
.. code-block:: ruby
|
||||||
|
|
||||||
include 'docker'
|
include 'docker'
|
||||||
|
|
||||||
Images
|
Images
|
||||||
~~~~~~
|
~~~~~~
|
||||||
@@ -51,26 +51,26 @@ Images
|
|||||||
The next step is probably to install a docker image, for this we have a
|
The next step is probably to install a docker image, for this we have a
|
||||||
defined type which can be used like so:
|
defined type which can be used like so:
|
||||||
|
|
||||||
.. code-block:: ruby
|
.. code-block:: ruby
|
||||||
|
|
||||||
docker::image { 'base': }
|
docker::image { 'base': }
|
||||||
|
|
||||||
This is equivalent to running:
|
This is equivalent to running:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
docker pull base
|
docker pull base
|
||||||
|
|
||||||
Note that it will only if the image of that name does not already exist.
|
Note that it will only if the image of that name does not already exist.
|
||||||
This is downloading a large binary so on first run can take a while.
|
This is downloading a large binary so on first run can take a while.
|
||||||
For that reason this define turns off the default 5 minute timeout
|
For that reason this define turns off the default 5 minute timeout
|
||||||
for exec. Note that you can also remove images you no longer need with:
|
for exec. Note that you can also remove images you no longer need with:
|
||||||
|
|
||||||
.. code-block:: ruby
|
.. code-block:: ruby
|
||||||
|
|
||||||
docker::image { 'base':
|
docker::image { 'base':
|
||||||
ensure => 'absent',
|
ensure => 'absent',
|
||||||
}
|
}
|
||||||
|
|
||||||
Containers
|
Containers
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
@@ -78,35 +78,35 @@ Containers
|
|||||||
Now you have an image you can run commands within a container managed by
|
Now you have an image you can run commands within a container managed by
|
||||||
docker.
|
docker.
|
||||||
|
|
||||||
.. code-block:: ruby
|
.. code-block:: ruby
|
||||||
|
|
||||||
docker::run { 'helloworld':
|
docker::run { 'helloworld':
|
||||||
image => 'base',
|
image => 'base',
|
||||||
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
|
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
|
||||||
}
|
}
|
||||||
|
|
||||||
This is equivalent to running the following command, but under upstart:
|
This is equivalent to running the following command, but under upstart:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done"
|
docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done"
|
||||||
|
|
||||||
Run also contains a number of optional parameters:
|
Run also contains a number of optional parameters:
|
||||||
|
|
||||||
.. code-block:: ruby
|
.. code-block:: ruby
|
||||||
|
|
||||||
docker::run { 'helloworld':
|
docker::run { 'helloworld':
|
||||||
image => 'base',
|
image => 'base',
|
||||||
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
|
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
|
||||||
ports => ['4444', '4555'],
|
ports => ['4444', '4555'],
|
||||||
volumes => ['/var/lib/counchdb', '/var/log'],
|
volumes => ['/var/lib/counchdb', '/var/log'],
|
||||||
volumes_from => '6446ea52fbc9',
|
volumes_from => '6446ea52fbc9',
|
||||||
memory_limit => 10485760, # bytes
|
memory_limit => 10485760, # bytes
|
||||||
username => 'example',
|
username => 'example',
|
||||||
hostname => 'example.com',
|
hostname => 'example.com',
|
||||||
env => ['FOO=BAR', 'FOO2=BAR2'],
|
env => ['FOO=BAR', 'FOO2=BAR2'],
|
||||||
dns => ['8.8.8.8', '8.8.4.4'],
|
dns => ['8.8.8.8', '8.8.4.4'],
|
||||||
}
|
}
|
||||||
|
|
||||||
Note that ports, env, dns and volumes can be set with either a single string
|
Note that ports, env, dns and volumes can be set with either a single string
|
||||||
or as above with an array of values.
|
or as above with an array of values.
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
Thatcher Penskens <thatcher@dotcloud.com>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Thatcher Penskens <thatcher@dotcloud.com>
|
||||||
@@ -89,9 +89,10 @@
|
|||||||
<li>
|
<li>
|
||||||
<p><strong>Install Docker</strong></p>
|
<p><strong>Install Docker</strong></p>
|
||||||
<p>Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.</p>
|
<p>Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.</p>
|
||||||
<p>You may see some warnings that the GPG keys cannot be verified.</p>
|
<p>This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).</p>
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list"</pre>
|
<pre>sudo apt-get install software-properties-common</pre>
|
||||||
|
<pre>sudo add-apt-repository ppa:dotcloud/lxc-docker</pre>
|
||||||
<pre>sudo apt-get update</pre>
|
<pre>sudo apt-get update</pre>
|
||||||
<pre>sudo apt-get install lxc-docker</pre>
|
<pre>sudo apt-get install lxc-docker</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func (graph *Graph) TempLayerArchive(id string, compression Compression, output
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, "Buffering to disk %v/%v (%v)"), tmp.Root)
|
return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, "Buffering to disk %v/%v (%v)", false), tmp.Root)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mktemp creates a temporary sub-directory inside the graph's filesystem.
|
// Mktemp creates a temporary sub-directory inside the graph's filesystem.
|
||||||
|
|||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
find $1 -name MAINTAINERS -exec cat {} ';' | sed -E -e 's/^[^:]*: *(.*)$/\1/' | grep -E -v -e '^ *$' -e '^ *#.*$' | sort -u
|
||||||
Executable
+58
@@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo >&2 "Usage: $0 PATH"
|
||||||
|
echo >&2 "Show the primary and secondary maintainers for a given path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DEST=$1
|
||||||
|
DESTFILE=""
|
||||||
|
if [ ! -d $DEST ]; then
|
||||||
|
DESTFILE=$(basename $DEST)
|
||||||
|
DEST=$(dirname $DEST)
|
||||||
|
fi
|
||||||
|
|
||||||
|
MAINTAINERS=()
|
||||||
|
cd $DEST
|
||||||
|
while true; do
|
||||||
|
if [ -e ./MAINTAINERS ]; then
|
||||||
|
{
|
||||||
|
while read line; do
|
||||||
|
re='^([^:]*): *(.*)$'
|
||||||
|
file=$(echo $line | sed -E -n "s/$re/\1/p")
|
||||||
|
if [ ! -z "$file" ]; then
|
||||||
|
if [ "$file" = "$DESTFILE" ]; then
|
||||||
|
echo "Override: $line"
|
||||||
|
maintainer=$(echo $line | sed -E -n "s/$re/\2/p")
|
||||||
|
MAINTAINERS=("$maintainer" "${MAINTAINERS[@]}")
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
MAINTAINERS+=("$line");
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
} < MAINTAINERS
|
||||||
|
fi
|
||||||
|
if [ -d .git ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if [ "$(pwd)" = "/" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
PRIMARY="${MAINTAINERS[0]}"
|
||||||
|
PRIMARY_FIRSTNAME=$(echo $PRIMARY | cut -d' ' -f1)
|
||||||
|
|
||||||
|
firstname() {
|
||||||
|
echo $1 | cut -d' ' -f1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "--- $PRIMARY is the PRIMARY MAINTAINER of $1. Assign pull requests to him."
|
||||||
|
echo "$(firstname $PRIMARY) may assign pull requests to the following secondary maintainers:"
|
||||||
|
for SECONDARY in "${MAINTAINERS[@]:1}"; do
|
||||||
|
echo "--- $SECONDARY"
|
||||||
|
done
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Daniel Mizyrycki <daniel@dotcloud.com>
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
lxc-docker (0.3.4-1) UNRELEASED; urgency=low
|
||||||
|
- Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile
|
||||||
|
- Builder: 'docker build -t FOO' applies the tag FOO to the newly built container.
|
||||||
|
- Runtime: interactive TTYs correctly handle window resize
|
||||||
|
- Runtime: fix how configuration is merged between layers
|
||||||
|
- Remote API: split stdout and stderr on 'docker run'
|
||||||
|
- Remote API: optionally listen on a different IP and port (use at your own risk)
|
||||||
|
- Documentation: improved install instructions.
|
||||||
|
|
||||||
|
-- dotCloud <ops@dotcloud.com> Thu, 30 May 2013 00:00:00 -0700
|
||||||
|
|
||||||
lxc-docker (0.3.2-1) UNRELEASED; urgency=low
|
lxc-docker (0.3.2-1) UNRELEASED; urgency=low
|
||||||
- Runtime: Store the actual archive on commit
|
- Runtime: Store the actual archive on commit
|
||||||
- Registry: Improve the checksum process
|
- Registry: Improve the checksum process
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
lxc-docker (0.3.4-1) precise; urgency=low
|
||||||
|
- Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile
|
||||||
|
- Builder: 'docker build -t FOO' applies the tag FOO to the newly built container.
|
||||||
|
- Runtime: interactive TTYs correctly handle window resize
|
||||||
|
- Runtime: fix how configuration is merged between layers
|
||||||
|
- Remote API: split stdout and stderr on 'docker run'
|
||||||
|
- Remote API: optionally listen on a different IP and port (use at your own risk)
|
||||||
|
- Documentation: improved install instructions.
|
||||||
|
|
||||||
|
-- dotCloud <ops@dotcloud.com> Thu, 30 May 2013 00:00:00 -0700
|
||||||
|
|
||||||
|
|
||||||
lxc-docker (0.3.3-1) precise; urgency=low
|
lxc-docker (0.3.3-1) precise; urgency=low
|
||||||
- Registry: Fix push regression
|
- Registry: Fix push regression
|
||||||
- Various bugfixes
|
- Various bugfixes
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Sam Alba <sam@dotcloud.com>
|
||||||
|
Joffrey Fuhrer <joffrey@dotcloud.com>
|
||||||
|
Ken Cochrane <ken@dotcloud.com>
|
||||||
@@ -330,6 +330,9 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat
|
|||||||
if validate {
|
if validate {
|
||||||
suffix = "images"
|
suffix = "images"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.Debugf("Image list pushed to index:\n%s\n", imgListJson)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson))
|
req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -428,9 +431,14 @@ func (r *Registry) ResetClient(authConfig *auth.AuthConfig) {
|
|||||||
r.client.Jar = cookiejar.NewCookieJar()
|
r.client.Jar = cookiejar.NewCookieJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) GetAuthConfig() *auth.AuthConfig {
|
func (r *Registry) GetAuthConfig(withPasswd bool) *auth.AuthConfig {
|
||||||
|
password := ""
|
||||||
|
if withPasswd {
|
||||||
|
password = r.authConfig.Password
|
||||||
|
}
|
||||||
return &auth.AuthConfig{
|
return &auth.AuthConfig{
|
||||||
Username: r.authConfig.Username,
|
Username: r.authConfig.Username,
|
||||||
|
Password: password,
|
||||||
Email: r.authConfig.Email,
|
Email: r.authConfig.Email,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-26
@@ -2,14 +2,15 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/registry"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -32,13 +33,6 @@ func nuke(runtime *Runtime) error {
|
|||||||
return os.RemoveAll(runtime.root)
|
return os.RemoveAll(runtime.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CopyDirectory(source, dest string) error {
|
|
||||||
if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func layerArchive(tarfile string) (io.Reader, error) {
|
func layerArchive(tarfile string) (io.Reader, error) {
|
||||||
// FIXME: need to close f somewhere
|
// FIXME: need to close f somewhere
|
||||||
f, err := os.Open(tarfile)
|
f, err := os.Open(tarfile)
|
||||||
@@ -71,15 +65,16 @@ func init() {
|
|||||||
|
|
||||||
// Create the "Server"
|
// Create the "Server"
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
registry: registry.NewRegistry(runtime.root),
|
|
||||||
}
|
}
|
||||||
// Retrieve the Image
|
// Retrieve the Image
|
||||||
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout); err != nil {
|
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, false); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: test that ImagePull(json=true) send correct json output
|
||||||
|
|
||||||
func newTestRuntime() (*Runtime, error) {
|
func newTestRuntime() (*Runtime, error) {
|
||||||
root, err := ioutil.TempDir("", "docker-test")
|
root, err := ioutil.TempDir("", "docker-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -88,7 +83,7 @@ func newTestRuntime() (*Runtime, error) {
|
|||||||
if err := os.Remove(root); err != nil {
|
if err := os.Remove(root); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := CopyDirectory(unitTestStoreBase, root); err != nil {
|
if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,24 +280,50 @@ func TestGet(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findAvailalblePort(runtime *Runtime, port int) (*Container, error) {
|
||||||
|
strPort := strconv.Itoa(port)
|
||||||
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
|
Image: GetTestImage(runtime).Id,
|
||||||
|
Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p " + strPort},
|
||||||
|
PortSpecs: []string{strPort},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := container.Start(); err != nil {
|
||||||
|
if strings.Contains(err.Error(), "address already in use") {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return container, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Run a container with a TCP port allocated, and test that it can receive connections on localhost
|
// Run a container with a TCP port allocated, and test that it can receive connections on localhost
|
||||||
func TestAllocatePortLocalhost(t *testing.T) {
|
func TestAllocatePortLocalhost(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
port := 5554
|
||||||
Image: GetTestImage(runtime).Id,
|
|
||||||
Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p 5555"},
|
var container *Container
|
||||||
PortSpecs: []string{"5555"},
|
for {
|
||||||
},
|
port += 1
|
||||||
)
|
log.Println("Trying port", port)
|
||||||
if err != nil {
|
t.Log("Trying port", port)
|
||||||
t.Fatal(err)
|
container, err = findAvailalblePort(runtime, port)
|
||||||
}
|
if container != nil {
|
||||||
if err := container.Start(); err != nil {
|
break
|
||||||
t.Fatal(err)
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println("Port", port, "already in use")
|
||||||
|
t.Log("Port", port, "already in use")
|
||||||
}
|
}
|
||||||
|
|
||||||
defer container.Kill()
|
defer container.Kill()
|
||||||
|
|
||||||
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
||||||
@@ -316,7 +337,7 @@ func TestAllocatePortLocalhost(t *testing.T) {
|
|||||||
|
|
||||||
conn, err := net.Dial("tcp",
|
conn, err := net.Dial("tcp",
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"localhost:%s", container.NetworkSettings.PortMapping["5555"],
|
"localhost:%s", container.NetworkSettings.PortMapping[strconv.Itoa(port)],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -345,7 +366,7 @@ func TestRestore(t *testing.T) {
|
|||||||
if err := os.Remove(root); err != nil {
|
if err := os.Remove(root); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := CopyDirectory(unitTestStoreBase, root); err != nil {
|
if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
||||||
results, err := srv.registry.SearchRepositories(term)
|
|
||||||
|
results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -67,40 +68,40 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
|||||||
return outs, nil
|
return outs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error {
|
func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, error) {
|
||||||
out = utils.NewWriteFlusher(out)
|
out = utils.NewWriteFlusher(out)
|
||||||
img, err := srv.runtime.repositories.LookupImage(name)
|
img, err := srv.runtime.repositories.LookupImage(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := utils.Download(url, out)
|
file, err := utils.Download(url, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
defer file.Body.Close()
|
defer file.Body.Close()
|
||||||
|
|
||||||
config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities)
|
config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
b := NewBuilder(srv.runtime)
|
b := NewBuilder(srv.runtime)
|
||||||
c, err := b.Create(config)
|
c, err := b.Create(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)"), path); err != nil {
|
if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)\r", false), path); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
// FIXME: Handle custom repo, tag comment, author
|
// FIXME: Handle custom repo, tag comment, author
|
||||||
img, err = b.Commit(c, "", "", img.Comment, img.Author, nil)
|
img, err = b.Commit(c, "", "", img.Comment, img.Author, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "%s\n", img.Id)
|
fmt.Fprintf(out, "%s\n", img.Id)
|
||||||
return nil
|
return img.ShortId(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagesViz(out io.Writer) error {
|
func (srv *Server) ImagesViz(out io.Writer) error {
|
||||||
@@ -291,9 +292,8 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error {
|
func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoint string, token []string, json bool) error {
|
||||||
out = utils.NewWriteFlusher(out)
|
history, err := r.GetRemoteHistory(imgId, endpoint, token)
|
||||||
history, err := srv.registry.GetRemoteHistory(imgId, registry, token)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -302,8 +302,8 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri
|
|||||||
// FIXME: Launch the getRemoteImage() in goroutines
|
// FIXME: Launch the getRemoteImage() in goroutines
|
||||||
for _, id := range history {
|
for _, id := range history {
|
||||||
if !srv.runtime.graph.Exists(id) {
|
if !srv.runtime.graph.Exists(id) {
|
||||||
fmt.Fprintf(out, "Pulling %s metadata\r\n", id)
|
fmt.Fprintf(out, utils.FormatStatus("Pulling %s metadata", json), id)
|
||||||
imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token)
|
imgJson, err := r.GetRemoteImageJson(id, endpoint, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// FIXME: Keep goging in case of error?
|
// FIXME: Keep goging in case of error?
|
||||||
return err
|
return err
|
||||||
@@ -314,12 +314,12 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the layer
|
// Get the layer
|
||||||
fmt.Fprintf(out, "Pulling %s fs layer\r\n", img.Id)
|
fmt.Fprintf(out, utils.FormatStatus("Pulling %s fs layer", json), id)
|
||||||
layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token)
|
layer, contentLength, err := r.GetRemoteImageLayer(img.Id, endpoint, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, "Downloading %v/%v (%v)"), false, img); err != nil {
|
if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, utils.FormatProgress("%v/%v (%v)", json), json), false, img); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,10 +327,9 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error {
|
func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, askedTag string, json bool) error {
|
||||||
out = utils.NewWriteFlusher(out)
|
fmt.Fprintf(out, utils.FormatStatus("Pulling repository %s from %s", json), remote, auth.IndexServerAddress())
|
||||||
fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress())
|
repoData, err := r.GetRepositoryData(remote)
|
||||||
repoData, err := srv.registry.GetRepositoryData(remote)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -342,7 +341,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
utils.Debugf("Retrieving the tag list")
|
utils.Debugf("Retrieving the tag list")
|
||||||
tagsList, err := srv.registry.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens)
|
tagsList, err := r.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -366,11 +365,11 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error
|
|||||||
utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id)
|
utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote)
|
fmt.Fprintf(out, utils.FormatStatus("Pulling image %s (%s) from %s", json), img.Id, img.Tag, remote)
|
||||||
success := false
|
success := false
|
||||||
for _, ep := range repoData.Endpoints {
|
for _, ep := range repoData.Endpoints {
|
||||||
if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil {
|
if err := srv.pullImage(r, out, img.Id, "https://"+ep+"/v1", repoData.Tokens, json); err != nil {
|
||||||
fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err)
|
fmt.Fprintf(out, utils.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n", json), askedTag, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
success = true
|
success = true
|
||||||
@@ -395,15 +394,17 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagePull(name, tag, registry string, out io.Writer) error {
|
func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, json bool) error {
|
||||||
if registry != "" {
|
r := registry.NewRegistry(srv.runtime.root)
|
||||||
if err := srv.pullImage(out, name, registry, nil); err != nil {
|
out = utils.NewWriteFlusher(out)
|
||||||
|
if endpoint != "" {
|
||||||
|
if err := srv.pullImage(r, out, name, endpoint, nil, json); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := srv.pullRepository(out, name, tag); err != nil {
|
if err := srv.pullRepository(r, out, name, tag, json); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,21 +477,20 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|||||||
return imgList, nil
|
return imgList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error {
|
func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name string, localRepo map[string]string) error {
|
||||||
out = utils.NewWriteFlusher(out)
|
out = utils.NewWriteFlusher(out)
|
||||||
fmt.Fprintf(out, "Processing checksums\n")
|
fmt.Fprintf(out, "Processing checksums\n")
|
||||||
imgList, err := srv.getImageList(localRepo)
|
imgList, err := srv.getImageList(localRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "Sending image list\n")
|
fmt.Fprintf(out, "Sending images list\n")
|
||||||
|
|
||||||
repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false)
|
repoData, err := r.PushImageJsonIndex(name, imgList, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Send only needed images
|
|
||||||
for _, ep := range repoData.Endpoints {
|
for _, ep := range repoData.Endpoints {
|
||||||
fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo))
|
fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo))
|
||||||
// For each image within the repo, push them
|
// For each image within the repo, push them
|
||||||
@@ -499,24 +499,24 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri
|
|||||||
fmt.Fprintf(out, "Image %s already on registry, skipping\n", name)
|
fmt.Fprintf(out, "Image %s already on registry, skipping\n", name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens); err != nil {
|
if err := srv.pushImage(r, out, name, elem.Id, ep, repoData.Tokens); err != nil {
|
||||||
// FIXME: Continue on error?
|
// FIXME: Continue on error?
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag)
|
fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag)
|
||||||
if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
if err := r.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := srv.registry.PushImageJsonIndex(name, imgList, true); err != nil {
|
if _, err := r.PushImageJsonIndex(name, imgList, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error {
|
func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId, ep string, token []string) error {
|
||||||
out = utils.NewWriteFlusher(out)
|
out = utils.NewWriteFlusher(out)
|
||||||
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -535,7 +535,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the json
|
// Send the json
|
||||||
if err := srv.registry.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
if err := r.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
||||||
if err == registry.ErrAlreadyExists {
|
if err == registry.ErrAlreadyExists {
|
||||||
fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id)
|
fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id)
|
||||||
return nil
|
return nil
|
||||||
@@ -570,20 +570,22 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the layer
|
// Send the layer
|
||||||
if err := srv.registry.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, ""), ep, token); err != nil {
|
if err := r.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, "", false), ep, token); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagePush(name, registry string, out io.Writer) error {
|
func (srv *Server) ImagePush(name, endpoint string, out io.Writer) error {
|
||||||
out = utils.NewWriteFlusher(out)
|
out = utils.NewWriteFlusher(out)
|
||||||
img, err := srv.runtime.graph.Get(name)
|
img, err := srv.runtime.graph.Get(name)
|
||||||
|
r := registry.NewRegistry(srv.runtime.root)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
|
fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
|
||||||
// If it fails, try to get the repository
|
// If it fails, try to get the repository
|
||||||
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
|
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
|
||||||
if err := srv.pushRepository(out, name, localRepo); err != nil {
|
if err := srv.pushRepository(r, out, name, localRepo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -592,7 +594,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "The push refers to an image: [%s]\n", name)
|
fmt.Fprintf(out, "The push refers to an image: [%s]\n", name)
|
||||||
if err := srv.pushImage(out, name, img.Id, registry, nil); err != nil {
|
if err := srv.pushImage(r, out, name, img.Id, endpoint, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -621,7 +623,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, "Importing %v/%v (%v)")
|
archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, "Importing %v/%v (%v)\r", false)
|
||||||
}
|
}
|
||||||
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -776,6 +778,13 @@ func (srv *Server) ContainerWait(name string) (int, error) {
|
|||||||
return 0, fmt.Errorf("No such container: %s", name)
|
return 0, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Server) ContainerResize(name string, h, w int) error {
|
||||||
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
|
return container.Resize(h, w)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("No such container: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error {
|
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error {
|
||||||
container := srv.runtime.Get(name)
|
container := srv.runtime.Get(name)
|
||||||
if container == nil {
|
if container == nil {
|
||||||
@@ -865,14 +874,12 @@ func NewServer(autoRestart bool) (*Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
registry: registry.NewRegistry(runtime.root),
|
|
||||||
}
|
}
|
||||||
runtime.srv = srv
|
runtime.srv = srv
|
||||||
return srv, nil
|
return srv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
registry *registry.Registry
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this failed once with a race condition ("Unable to remove filesystem for xxx: directory not empty")
|
||||||
if err = srv.ContainerDestroy(id, true); err != nil {
|
if err = srv.ContainerDestroy(id, true); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-2
@@ -109,17 +109,35 @@ type State struct {
|
|||||||
termios Termios
|
termios Termios
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Winsize struct {
|
||||||
|
Width uint16
|
||||||
|
Height uint16
|
||||||
|
x uint16
|
||||||
|
y uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||||
|
ws := &Winsize{}
|
||||||
|
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
|
||||||
|
return ws, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetWinsize(fd uintptr, ws *Winsize) error {
|
||||||
|
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws)))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||||
func IsTerminal(fd int) bool {
|
func IsTerminal(fd int) bool {
|
||||||
var termios Termios
|
var termios Termios
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&termios)))
|
||||||
return err == 0
|
return err == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore restores the terminal connected to the given file descriptor to a
|
// Restore restores the terminal connected to the given file descriptor to a
|
||||||
// previous state.
|
// previous state.
|
||||||
func Restore(fd int, state *State) error {
|
func Restore(fd int, state *State) error {
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
|
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Daniel Mizyrycki <daniel@dotcloud.com>
|
||||||
@@ -49,10 +49,10 @@ func CompareConfig(a, b *Config) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MergeConfig(userConf, imageConf *Config) {
|
func MergeConfig(userConf, imageConf *Config) {
|
||||||
if userConf.Hostname != "" {
|
if userConf.Hostname == "" {
|
||||||
userConf.Hostname = imageConf.Hostname
|
userConf.Hostname = imageConf.Hostname
|
||||||
}
|
}
|
||||||
if userConf.User != "" {
|
if userConf.User == "" {
|
||||||
userConf.User = imageConf.User
|
userConf.User = imageConf.User
|
||||||
}
|
}
|
||||||
if userConf.Memory == 0 {
|
if userConf.Memory == 0 {
|
||||||
|
|||||||
+28
-6
@@ -69,6 +69,7 @@ type progressReader struct {
|
|||||||
readProgress int // How much has been read so far (bytes)
|
readProgress int // How much has been read so far (bytes)
|
||||||
lastUpdate int // How many bytes read at least update
|
lastUpdate int // How many bytes read at least update
|
||||||
template string // Template to print. Default "%v/%v (%v)"
|
template string // Template to print. Default "%v/%v (%v)"
|
||||||
|
json bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *progressReader) Read(p []byte) (n int, err error) {
|
func (r *progressReader) Read(p []byte) (n int, err error) {
|
||||||
@@ -84,15 +85,15 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
if r.readProgress-r.lastUpdate > updateEvery || err != nil {
|
if r.readProgress-r.lastUpdate > updateEvery || err != nil {
|
||||||
if r.readTotal > 0 {
|
if r.readTotal > 0 {
|
||||||
fmt.Fprintf(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100))
|
fmt.Fprintf(r.output, r.template, r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(r.output, r.template+"\r", r.readProgress, "?", "n/a")
|
fmt.Fprintf(r.output, r.template, r.readProgress, "?", "n/a")
|
||||||
}
|
}
|
||||||
r.lastUpdate = r.readProgress
|
r.lastUpdate = r.readProgress
|
||||||
}
|
}
|
||||||
// Send newline when complete
|
// Send newline when complete
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(r.output, "\n")
|
fmt.Fprintf(r.output, FormatStatus("", r.json))
|
||||||
}
|
}
|
||||||
|
|
||||||
return read, err
|
return read, err
|
||||||
@@ -100,11 +101,11 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
|
|||||||
func (r *progressReader) Close() error {
|
func (r *progressReader) Close() error {
|
||||||
return io.ReadCloser(r.reader).Close()
|
return io.ReadCloser(r.reader).Close()
|
||||||
}
|
}
|
||||||
func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string) *progressReader {
|
func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, json bool) *progressReader {
|
||||||
if template == "" {
|
if template == "" {
|
||||||
template = "%v/%v (%v)"
|
template = "%v/%v (%v)\r"
|
||||||
}
|
}
|
||||||
return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template}
|
return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HumanDuration returns a human-readable approximation of a duration
|
// HumanDuration returns a human-readable approximation of a duration
|
||||||
@@ -531,6 +532,13 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyDirectory(source, dest string) error {
|
||||||
|
if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil {
|
||||||
|
return fmt.Errorf("Error copy: %s (%s)", err, output)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type NopFlusher struct{}
|
type NopFlusher struct{}
|
||||||
|
|
||||||
func (f *NopFlusher) Flush() {}
|
func (f *NopFlusher) Flush() {}
|
||||||
@@ -555,3 +563,17 @@ func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
|||||||
}
|
}
|
||||||
return &WriteFlusher{w: w, flusher: flusher}
|
return &WriteFlusher{w: w, flusher: flusher}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FormatStatus(str string, json bool) string {
|
||||||
|
if json {
|
||||||
|
return "{\"status\" : \"" + str + "\"}"
|
||||||
|
}
|
||||||
|
return str + "\r\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatProgress(str string, json bool) string {
|
||||||
|
if json {
|
||||||
|
return "{\"progress\" : \"" + str + "\"}"
|
||||||
|
}
|
||||||
|
return "Downloading " + str + "\r"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user