欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【MacOS】Docker的安装和基本使用

程序员文章站 2022-04-07 14:38:05
...

1. 下载安装

Docker Desktop for Mac
双击下载好的Docker.dmg, 然后将图标拽到application里:【MacOS】Docker的安装和基本使用
【MacOS】Docker的安装和基本使用

如果没有账号,请先注册。会收到一封verify的邮件,点击之后login,输入账号和密码。

2.使用

打开terminal 查看我们的version:

$ docker version

output:

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:22:34 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  ...
  ...

干活喜欢先看“使用手册”:

$ docker build --help

output:

Usage:	docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Options:
      --add-host list           Add a custom host-to-IP mapping (host:ip)
      --build-arg list          Set build-time variables
      --cache-from strings      Images to consider as cache sources
      --cgroup-parent string    Optional parent cgroup for the container
      --compress                Compress the build context using gzip
      --cpu-period int          Limit the CPU CFS (Completely Fair
                                Scheduler) period
      --cpu-quota int           Limit the CPU CFS (Completely Fair
                                Scheduler) quota
  -c, --cpu-shares int          CPU shares (relative weight)
      --cpuset-cpus string      CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string      MEMs in which to allow execution (0-3, 0,1)
      --disable-content-trust   Skip image verification (default true)
  -f, --file string             Name of the Dockerfile (Default is
                                'PATH/Dockerfile')
      --force-rm                Always remove intermediate containers
      --iidfile string          Write the image ID to the file
      --isolation string        Container isolation technology
      --label list              Set metadata for an image
  -m, --memory bytes            Memory limit
      --memory-swap bytes       Swap limit equal to memory plus swap:
                                '-1' to enable unlimited swap
      --network string          Set the networking mode for the RUN
                                instructions during build (default "default")
      --no-cache                Do not use cache when building the image
      --pull                    Always attempt to pull a newer version of
                                the image
  -q, --quiet                   Suppress the build output and print image
                                ID on success
      --rm                      Remove intermediate containers after a
                                successful build (default true)
      --security-opt strings    Security options
      --shm-size bytes          Size of /dev/shm
  -t, --tag list                Name and optionally a tag in the
                                'name:tag' format
      --target string           Set the target build stage to build.
      --ulimit ulimit           Ulimit options (default [])

3. 建立第一个Container:

下面我们来下载一个例子,例子里面有我们搞第一个docker需要的所有的东西:

$ git clone https://github.com/docker/doodle.git

output:

Cloning into 'doodle'...

remote: Enumerating objects: 73, done.
remote: Total 73 (delta 0), reused 0 (delta 0), pack-reused 73
Unpacking objects: 100% (73/73), done.

下载完成,打开文件夹:

cd doodle/cheers2019

开建! tag咱们的Docker image:

A Docker image is a private filesystem, just for your container. It provides all the files and code your container will need. Running the docker build command creates a Docker image using the Dockerfile. This built image is in your machine’s local Docker image registry.

语法是docker build [OPTIONS] PATH | URL | -
这里我们使用:
[OPTIONS] : -t
PATH : [改成你的用户名]/cheers2019 譬如我的就是loewi/cheers2019
URL: .

$ docker build -t [你的用户名]/cheers2019 .

下面我们就可以跑我们第一个Container了

Running a container launches your software with private resources, securely isolated from the rest of your machine.

$ docker run -it --rm [你的用户名]/cheers2019

CHEERS!!!!
【MacOS】Docker的安装和基本使用
我们可以将这个image分享到Docker Hub

Once you’re ready to share your container with the world, push the image that describes it to Docker Hub.

$ docker login && docker push [你的用户名]/cheers2019

Output:

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: [填你的用户名]
Password: [填你的密码]

Login Succeeded
The push refers to repository [docker.io/loewi/cheers2019]
ade970f14012: Pushed 
latest: digest: sha256:1637a2c7b794ded4790852ebe1c9c7be63728966790d4c3d30bbf8515fbfb916 size: 528

这时候去看你的Docker Hub,就能显示出你push的image啦!
【MacOS】Docker的安装和基本使用

更多的Containers等你去发现。

  1. 安装tensorflow

Tensorflow的Docker Hub

$ docker pull tensorflow/tensorflow

output:

Using default tag: latest
latest: Pulling from tensorflow/tensorflow
2746a4a261c9: Pull complete 
4c1d20cdee96: Pull complete 
0d3160e1d0de: Pull complete 
c8e37668deea: Pull complete 
e52cad4ccd83: Pull complete 
fac2cc420193: Pull complete 
3cae0d3239d1: Pull complete 
d383bce69b6c: Pull complete 
8a90b3d85a18: Pull complete 
4baf29878469: Pull complete 
4475017ba949: Pull complete 
Digest: sha256:cec133a881c7....
Status: Downloaded newer image for tensorflow/tensorflow:latest
docker.io/tensorflow/tensorflow:latest 
相关标签: 安装