docker在ubuntu16.04下的安装

安装docker

主机环境 ubuntu16.04

curl -sSL https://get.daocloud.io/docker >>install.sh
sh install.sh --mirror Aliyun

测试安装完成

root@base2018:/home/tb# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pulling fs layer 
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/f2/f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7/data?Expires=1523309522&Signature=Infe2tgv51xWB5QQA0EaDmJv0ETkvaewuieEpDGkLlMKQR9a4Seglpmk1sJhFkypTPUWBwvfUK6JIem5Jiwk1J9PITbvuTAs3w55weLM3cy3TaGF3so5QJgQKY9TsAaQ7Zi9qnLaZ8PexJlF9lkSvFEP7KiW640m72n6MzMVBoM_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.
See 'docker run --help'.

出现net/http: TLS handshake timeout,一般是镜像在墙外,够不着手。

我们手动加一个配置

root@base2018:/home/tb# vim /etc/docker/daemon.json

内容如下:

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

然后重启docker,看看状态

root@base2018:/home/tb# service docker stop
root@base2018:/home/tb# service docker start
root@base2018:/home/tb# service docker status

安装成功

root@base2018:/home/tb# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

构件自己的docker环境

phpdocker.io构件自己需要的php环境,generate project archive之后是一个zip包,里面内容大概如下

root@base2018:/home/tb# unzip xincron.zip 
Archive:  mycron.zip
  inflating: phpdocker/README.md     
  inflating: phpdocker/README.html   
  inflating: phpdocker/php-fpm/Dockerfile  
  inflating: phpdocker/php-fpm/php-ini-overrides.ini  
  inflating: phpdocker/nginx/nginx.conf  
  inflating: docker-compose.yml 

然后需要在能引用到docker-compose.yml 的地方,执行

root@base2018:/home/tb#  docker-compose up
The program 'docker-compose' is currently not installed. You can install it by typing:
apt install docker-compose

没有安装docker-compose,那么安装一下,注意用的是daocloude的镜像

root@base2018:/home/tb# curl -L https://get.daocloud.io/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   423  100   423    0     0   2887      0 --:--:-- --:--:-- --:--:--  2897
100 10.3M  100 10.3M    0     0  1019k      0  0:00:10  0:00:10 --:--:-- 1882k
root@base2018:/home/tb# chmod +x /usr/local/bin/docker-compose

再次 docker-compose up,经过以下输出。等待。。

root@base2018:/home/tb# docker-compose up
Creating network "tb_default" with the default driver
Pulling webserver (nginx:alpine)...
alpine: Pulling from library/nginx
ff3a5c916c92: Pull complete
f9c32daa8fe9: Pull complete
655cd391f0aa: Pull complete
64b82947328a: Pull complete
Digest: sha256:e0f3f5ebde753fa44b5fcdc771fc89f117ee8b2bbcece1c1bdf35f2de4da4e0b
Status: Downloaded newer image for nginx:alpine
Building php-fpm
Step 1/3 : FROM phpdockerio/php56-fpm:latest
latest: Pulling from phpdockerio/php56-fpm
f2b6b4884fc8: Pull complete
c70792025682: Pull complete
4f4f46587b8b: Pull complete
2a42286c9da1: Pull complete
4c18e6e61b91: Pull complete
Digest: sha256:f7b330cab7f5dd6101b4824990c9bf4af5e78c3ea1d7c8259e84f5ddd3bd6608
Status: Downloaded newer image for phpdockerio/php56-fpm:latest
 ---> e944c32c61aa
Step 2/3 : WORKDIR "/application"
Removing intermediate container 297a0cbcbcc5
...

查看docker镜像状态

root@base2018:/home/tb# docker-compose ps
      Name                     Command               State          Ports        
---------------------------------------------------------------------------------
xincron-php-fpm     /bin/sh -c /usr/sbin/php5- ...   Up      9000/tcp            
xincron-webserver   nginx -g daemon off;             Up      0.0.0.0:8056->80/tcp

这里对比一下刚刚压缩包里的配置文件

version: "3.1"
services:

    webserver:
      image: nginx:alpine
      container_name: xincron-webserver
      working_dir: /application
      volumes:
          - .:/application
          - ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      ports:
       - "8056:80"

    php-fpm:
      build: phpdocker/php-fpm
      container_name: xincron-php-fpm
      working_dir: /application
      volumes:
        - .:/application
        - ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php5/fpm/conf.d/99-overrides.ini

对比一下可以发现一些东西,对吧。

查看所有docker状态

root@base2018:/home/tb# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                         PORTS               NAMES
2916156f654e        nginx:latest        "nginx -g 'daemon of…"   About a minute ago   Exited (0) 19 seconds ago                          unruffled_mcnulty
e9d2470dfdf9        nginx:latest        "nginx -g 'daemon of…"   5 minutes ago        Exited (0) 4 minutes ago                           quizzical_thompson
69f97e182e72        nginx               "nginx -g 'daemon of…"   25 minutes ago       Exited (0) 4 minutes ago                           festive_fermat
44bcd14133af        nginx:alpine        "nginx -g 'daemon of…"   37 minutes ago       Exited (0) 12 seconds ago                          xincron-webserver
3195a5d6b6e4        tb_php-fpm          "/bin/sh -c '/usr/sb…"   37 minutes ago       Exited (137) 9 seconds ago                         xincron-php-fpm
610b22716262        hello-world         "/hello"                 About an hour ago    Exited (0) About an hour ago                       epic_archimedes
ef7be27e9f00        hello-world         "/hello"                 About an hour ago    Exited (0) About an hour ago                       nostalgic_lamport

启动某个docke

root@base2018:/home/tb# docker run -tid nginx:latest /bin/bash 

进入某个docker

root@base2018:/home/tb# docker attach cfd496533308
root@cfd496533308:/# ls
bin  boot  dev    etc  home  lib    lib64  media  mnt  opt    proc  root  run  sbin  srv  sys  tmp  usr  var
root@cfd496533308:/# 

参考之前的docker一篇文章

    原文作者:牙小木木
    原文地址: https://segmentfault.com/a/1190000014266779
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞