Docker初体验——踩过的那些坑!

2018‎年‎3‎月‎6‎日


Docker安装

环境:windows7

安装包:DockerToolbox-17.10.0-ce.exe (下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/)

//启动包错:
Running pre-create checks...  
(default) No default Boot2Docker ISO found locally, downloading the latest release...  

//之后下载ISO 然后被墙。。。

原因:其实这个报错不需要下载最新ISO文件,而是Boot2Docker文件没有放到正确的位置。

解决:复制安装目录下的boot2docker.iso到C:\Users\Administrator.Docker\machine\cache到这个目录下。

//启动报错:
Error creating machine: Error in driver during machine creation:This computer doesn't have VT-X/AMD-v 
enabled. Enabling it in the BIOS is mandatory

原因:BIOS没有开启虚拟化

解决:这时就要启动BIOS的虚拟化设置 | 开启CPU虚拟化支持。 重启电脑后按F2或F10进入BIOS界面(不同主板型号进入BIOS所需按键不同)。 进入BIOS界面:Intel Virtualization Technology > Enabled。


端口映射

环境:windows7(Linux下可能不存在这个问题)

//在docker下部署了web应用服务并进行了端口映射。部署完成后,在浏览器中输入localhost:port无法访问对应的web服务

原因:原来,docker是运行在Linux上的,在Windows中运行docker,实际上还是在Windows下先安装了一个Linux环境,然后在这个系统中运行的docker。也就是说,服务中使用的localhost指的是这个Linux环境的地址,而不是我们的宿主环境Windows。

解决:输入以下命令查找这个的Linux ip 使用这个ip地址加端口号(ip:port)访问web应用,访问成功。

#这个ip地址一般为192.168.99.100
docker-machine ip default

2018‎年‎3‎月‎7‎日


环境:windows7

: 使用docker build 创建新景象,写好Dockerfile后运行命令

$ docker build -t test/centos:6.7 .

#报以下错误

$ error checking context: 'can't stat '\\?\C:\Users\Administrator\AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application ...

原因:Dockerfile保存位置不对。

解决:正确做法 创建dockerfiles文件夹并进入文件夹:

$ mkdir dockerfiles
$ cd dockerfiles

创建并编辑Dockerfile文件:

$ touch Dockerfile
$ vi Dockerfile

执行docker build 命令:

docker build -t test/centos:6.7 .

2018年3月8号


使用docker两天的感受:一定要看官网文档(最好是英文),不要使用国内哪些所谓的教程!!!不要问我为什么???(坑太多。。。)


2018年3月9号


: 使用swarm 新建集群时遇到双网卡,未指定IP 报以下错误

Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on eth0 and 192.168.99.100 on eth1) - specify one with --advertise-addr

原因:由于有两个IP,集群不知道使用哪个所以报错。

解决:解决方法报错信息已经给出提示,使用--advertise-addr 指定IP

$docker swarm init --advertise-addr 192.168.99.100

: 使用 docker-compose.yml 运行docker 官网例子时报错

$docker stack deploy -c docker-compose.yml getstartedlab

networks Additional property networks is not allowed
#类似错误
replicas Additional property replicas is not allowed
...

原因:docker-compose.yml文件缩进不正确

官网版本

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    image: username/repo:tag
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

我的版本

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    image: username/repo:tag
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
        restart_policy: #缩进错误
          condition: on-failure #缩进错误
      ports: #缩进错误
        - "80:80" #缩进错误
      networks: #缩进错误
        - webnet #缩进错误
networks:
  webnet:

解决:修改缩进错误,重新运行命令,一切正常。

猜你喜欢

转载自my.oschina.net/u/1036767/blog/1630330