当前位置:   article > 正文

Mac系统docker安装配置及基本使用_mac安装docker

mac安装docker

1、下载并安装

地址:https://hub.docker.com/editions/community/docker-ce-desktop-mac/

安装完成后,启动Docker,点击鲸鱼图标可显示docker的相关操作,如下图。

2、配置镜像加速

在国内访问默认的官方镜像速度较慢,可使用阿里云的镜像加速,注册阿里账号并申请容器服务之后,可在 这里 查看分配的镜像加速地址。然后在Docker的Preferences中配置加速地址。

3、注册Docker ID

完成上面两个步骤就可以正常使用docker,注册Docker ID是为了便于管理自己的镜像,注册地址:https://hub.docker.com/

注册完成后可在Mac版Docker桌面工具中登录,并查看自己已有的镜像。

  

4、基本使用

4.1 docker命令

进入终端,输入docker回车,可查看docker支持的命令,如下

  1. Usage: docker [OPTIONS] COMMAND
  2. A self-sufficient runtime for containers
  3. Options:
  4. --config string Location of client config files (default "/Users/crane/.docker")
  5. -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
  6. -D, --debug Enable debug mode
  7. -H, --host list Daemon socket(s) to connect to
  8. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  9. --tls Use TLS; implied by --tlsverify
  10. --tlscacert string Trust certs signed only by this CA (default "/Users/crane/.docker/ca.pem")
  11. --tlscert string Path to TLS certificate file (default "/Users/crane/.docker/cert.pem")
  12. --tlskey string Path to TLS key file (default "/Users/crane/.docker/key.pem")
  13. --tlsverify Use TLS and verify the remote
  14. -v, --version Print version information and quit
  15. Management Commands:
  16. app* Docker Application (Docker Inc., v0.8.0)
  17. builder Manage builds
  18. buildx* Build with BuildKit (Docker Inc., v0.3.1-tp-docker)
  19. checkpoint Manage checkpoints
  20. config Manage Docker configs
  21. container Manage containers
  22. context Manage contexts
  23. image Manage images
  24. manifest Manage Docker image manifests and manifest lists
  25. network Manage networks
  26. node Manage Swarm nodes
  27. plugin Manage plugins
  28. secret Manage Docker secrets
  29. service Manage services
  30. stack Manage Docker stacks
  31. swarm Manage Swarm
  32. system Manage Docker
  33. trust Manage trust on Docker images
  34. volume Manage volumes
  35. Commands:
  36. attach Attach local standard input, output, and error streams to a running container
  37. build Build an image from a Dockerfile
  38. commit Create a new image from a container's changes
  39. cp Copy files/folders between a container and the local filesystem
  40. create Create a new container
  41. deploy Deploy a new stack or update an existing stack
  42. diff Inspect changes to files or directories on a container's filesystem
  43. events Get real time events from the server
  44. exec Run a command in a running container
  45. export Export a container's filesystem as a tar archive
  46. history Show the history of an image
  47. images List images
  48. import Import the contents from a tarball to create a filesystem image
  49. info Display system-wide information
  50. inspect Return low-level information on Docker objects
  51. kill Kill one or more running containers
  52. load Load an image from a tar archive or STDIN
  53. login Log in to a Docker registry
  54. logout Log out from a Docker registry
  55. logs Fetch the logs of a container
  56. pause Pause all processes within one or more containers
  57. port List port mappings or a specific mapping for the container
  58. ps List containers
  59. pull Pull an image or a repository from a registry
  60. push Push an image or a repository to a registry
  61. rename Rename a container
  62. restart Restart one or more containers
  63. rm Remove one or more containers
  64. rmi Remove one or more images
  65. run Run a command in a new container
  66. save Save one or more images to a tar archive (streamed to STDOUT by default)
  67. search Search the Docker Hub for images
  68. start Start one or more stopped containers
  69. stats Display a live stream of container(s) resource usage statistics
  70. stop Stop one or more running containers
  71. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  72. top Display the running processes of a container
  73. unpause Unpause all processes within one or more containers
  74. update Update configuration of one or more containers
  75. version Show the Docker version information
  76. wait Block until one or more containers stop, then print their exit codes
  77. Run 'docker COMMAND --help' for more information on a command.

4.2 搜索镜像

比如我们搜索nginx镜像,命令如下,搜索结果中标记“OFFICIAL”的为官方镜像,其他为用户自定义镜像,可根据实际需要选择。

docker search nginx

4.3 获取镜像

搜索到了需要的镜像之后可使用如下命令将镜像拉取到本地,类似于git拉取代码。

  1. # 拉取指定版本xxx镜像
  2. # docker pull nginx:xxx
  3. # 拉取最新版本镜像 等价于docker pull nginx:latest
  4. docker pull nginx

4.4 创建并启动容器

镜像拉取成功后,使用下面的命令启动nginx容器,容器内部的80端口已经映射到了本机的8080端口,所以启动成功后可以使用http://localhost:8080/访问docker容器内部nginx80端口映射的地址。

  1. # -d 后台运行
  2. # -p 8080:80 宿主机的8080端口映射到docker内部的80端口
  3. # --name docker-nginx 启动后的容器名称为docker-nginx
  4. docker run -d -p 8080:80 --name docker-nginx nginx

4.5 查看及停止容器

查看容器基本命令如下

  1. # 查看运行中的容器
  2. docker ps
  3. # 查看所有容器 包括正在运行和已经停止运行的
  4. docker ps -a

停止容器命令如下

  1. # 通过id直接关闭容器
  2. # docker kill a0fbf4519279
  3. # 通过容器名称直接关闭容器
  4. docker kill docker-nginx
  5. # 通过id直接容器 默认等待十秒 超时强制关闭
  6. # docker stop a0fbf4519279
  7. # 通过容器名称关闭容器 默认等待十秒 超时强制关闭 等价于 docker stop -t=10 docker-nginx
  8. docker stop docker-nginx

 

4.6 启动停止的容器

命令如下

  1. # 启动容器可通过容器id或者容器名称
  2. # 通过容器名称启动容器,如果已启动则忽略
  3. docker start docker-nginx
  4. # 通过容器名称重新启动容器,如果未启动则直接启动,如果已启动则关闭再启动
  5. # docker restart docker-nginx

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/48932
推荐阅读
相关标签
  

闽ICP备14008679号