docker使用

1.本机安装的容器

    sudo docker ps -a

  查看最新的创建的容器
    
    sudo docker ps -l

2.本机上的镜像

    sudo docker images

3.在docker hub 上搜索镜像

    sudo docker search tensorflow


NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tensorflow/tensorflow                      Official docker images for deep learning f...   506                  
xblaster/tensorflow-jupyter                Dockerized Jupyter with tensorflow              39                   [OK]
jupyter/tensorflow-notebook                Jupyter Notebook Scientific Python Stack w...   18                   
romilly/rpi-docker-tensorflow              Tensorflow and Jupyter running in docker c...   14                   
erroneousboat/tensorflow-python3-jupyter   Docker container with python 3 version of ...   6                    [OK]
satoshun/tensorflow-notebook               Jupyter with Tensorflow                         5                    [OK]
floydhub/tensorflow                        tensorflow                                      3                    [OK]
mochin/tensorflow-serving                  tensorflow-serving                              3                    [OK]
tensorflow/tf_grpc_server                  Server for TensorFlow GRPC Distributed Run...   3                    
eboraas/tensorflow                         TensorFlow with Jupyter Notebook, includin...   2                    [OK]
hytssk/tensorflow                          tensorflow image with matplotlib.pyplot.im...   2                    [OK]
tensorflow/tf_grpc_test_server             Testing server for GRPC-based distributed ...   2                    
bitnami/tensorflow-serving                 Bitnami Docker Image for TensorFlow Serving     1                    [OK]
djpetti/rpinets-tensorflow                 Tensorflow container that is ready to be u...   0                    [OK]
opensciencegrid/tensorflow-gpu             TensorFlow GPU set up for OSG                   0                    
opensciencegrid/tensorflow                 TensorFlow image with some OSG additions        0                    
eywalker/tensorflow                        Docker image for TensorFlow ready environm...   0                    
eywalker/tensorflow-jupyter                TensorFlow images designed to launch Jupyt...   0                    
sunkeun/tensorflow-aws-gpu                 Tensorflow AWS GPU                              0                    [OK]
fluxcapacitor/prediction-tensorflow                                                        0                    
mediadesignpractices/tensorflow            Tensorflow w/ CUDA (GPU) + extras               0                    [OK]
abhishek404/tensorflow-gpu                 Tensorflow GPU image                            0                    
lab41/tensorflow-notebook                                                                  0                    
davidchiu/tensorflow09                     tensorflow09 with GPU support                   0                    
alfpark/tensorflow                         TensorFlow                                      0                    




4.删除本机镜像先要删除容器,否则报错:

py@ubuntu:~$ sudo docker rmi 1815c82652c0  
Error response from daemon: conflict: unable to delete 1815c82652c0 (must be forced) - image is being used by stopped container b766544e7942

正确的删除方法:
    删除指定id的容器
    py@ubuntu:~$ sudo docker rm b766544e7942
    b766544e7942

    删除指定id的镜像
    py@ubuntu:~$ sudo docker rmi 1815c82652c0  
    Untagged: hello-world:latest
    Untagged: hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
    Deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
    Deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a



5.查看本机的docker版本
    py@ubuntu:~$ sudo docker version
Client:
 Version:      17.06.1-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:51:12 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.1-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:50:04 2017
 OS/Arch:      linux/amd64
 Experimental: false



6.查看更详细的关于某一个容器的信息,可以使用镜像id的前面部分,不需要完整的id。

    sudo docker inspect (容器id)




py@ubuntu:~$ sudo docker inspect 35e1992cb249
[
    {
        "Id": "35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d",
        "Created": "2017-08-28T09:14:57.318799893Z",
        "Path": "/bin/echo",
        "Args": [
            "Hello world"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-08-28T09:14:58.186476391Z",
            "FinishedAt": "2017-08-28T09:14:58.257329481Z"
        },
        "Image": "sha256:ccc7a11d65b1b5874b65adb4b2387034582d08d65ac1817ebc5fb9be1baa5f88",
        "ResolvConfPath": "/var/lib/docker/containers/35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d/hostname",
        "HostsPath": "/var/lib/docker/containers/35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d/hosts",
        "LogPath": "/var/lib/docker/containers/35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d/35e1992cb249375287ced2ac534c844b43dd7cf12548c567295abd4df424cc6d-json.log",
        "Name": "/confident_einstein",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "35e1992cb249",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/echo",
                "Hello world"
            ],
            "Image": "ubuntu",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "155fc18684c273b3daf6b7c708850aa11a1c4624d744521bb55720e881c8492a",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/155fc18684c2",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "4ce07b9fd8a7dce0a87289a601d2ae6b0dedb29375114affd69ada6e46fdfa34",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]





7.拉取镜像

    sudo docker pull tensorflow/tensorflow
Using default tag: latest
latest: Pulling from tensorflow/tensorflow
d5c6f90da05d: Already exists
1300883d87d5: Already exists
c220aa3cfc1b: Already exists
2e9398f099dc: Already exists
dc27a084064f: Already exists
ac20e1750c7a: Pull complete
5eb5e7cac016: Pull complete
559f0c8c16df: Pull complete
a87ddd485328: Pull complete
e51c4834e0e9: Pull complete
ce3f24dd1116: Pull complete
32b04708f9fa: Pull complete
Digest: sha256:4b014f1ddfdaf046a02c7477de5a2053f93d68f4d6dcf8462344383520c264b9
Status: Downloaded newer image for tensorflow/tensorflow:latest

8.运行一个镜像的容器

    sudo mkdir -p /data/tensorflow/notebooks

    sudo docker run -it   --name mytensorflow -v /data/tensorflow/notebooks:/notebooks -p 8888:8888  tensorflow/tensorflow
启动的时候并不是daemon 模式的,而是前台模式,同时显示了运行的日志。
    [I 02:40:08.286 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 02:40:08.353 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 02:40:08.377 NotebookApp] Serving notebooks from local directory: /notebooks
[I 02:40:08.377 NotebookApp] 0 active kernels
[I 02:40:08.377 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=1775ab799ca7a6f023988057a623b3a0ba30b5017e0a1187
[I 02:40:08.378 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 02:40:08.379 NotebookApp]
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=1775ab799ca7a6f023988057a623b3a0ba30b5017e0a1187


    sudo docker run -it -d  --name mytensorflow -v /data/tensorflow/notebooks:/notebooks -p 8888:8888  tensorflow/tensorflow

在后台运行刚才的容器

    sudo docker start  mytensorflow


9.进入容器,然后可以执行安装等操作

    py@ubuntu:~$ sudo docker exec -it  mytensorflow bash
root@d87c904ff7a9:/notebooks#

    从容器退回到宿主机
root@d87c904ff7a9:/notebooks# exit


10.将本地文件复制到容器中

     sudo docker cp  ./Desktop/jdk-8u144-linux-x64.tar.gz  mycontainer:/usr/local







































posted @ 2017-12-28 10:21  深渊中的鱼  阅读(921)  评论(0编辑  收藏  举报