美文网首页
docker的初使用

docker的初使用

作者: liamu | 来源:发表于2018-08-07 15:02 被阅读19次

进官网

安装

sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88 //安全性校验
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
apt-cache madison docker-ce
sudo apt-get install docker-ce=
sudo apt-get install docker-ce=17.06.2~ce-0~ubuntu
sudo docker run hello-world

卸载

sudo apt-get purge docker-ce
sudo rm -rf /var/lib/docker

创建docker专属用户

sudo groupadd docker
sudo systemctl enable docker
sudo systemctl disable docker 

镜像的使用

docker ps  // 显示状态为运行(Up)的容器
docker rm $docker_name
docker stop # 停止容器运行,发送信号SIGTERM,例如:docker stop mycon
docker start # 启动一个停止状态的容器,例如:docker start mycon
docker restart # 重启一个容器,例如:docker restart mycon
docker rm # 删除一个容器,例如:doecker rm mycon
docker kill # 发送信号给容器,默认SIGKILL,例如:docker kill -s KILL mycon (-s表示向容器发送一个信号)
docker logs -f mycon(查看容器mycon的日志输出)

docker cp /www/test mycon:/www/  #将主机/www/test目录拷贝到容器mycon的/www目录下
docker cp /www/test mycon:/www   #将主机/www/test目录拷贝到容器mycon中,目录重命名为www
docker cp mycon:/www /tmp/test    #将容器mycon中的/www目录拷贝到主机的/tmp/test目录中

docker images # 显示本地所有的镜像列表
docker import my_ubuntu_v3.tar my/ubuntu:v4    #从镜像归档文件my_ubuntu_v3.tar创建镜像,命名为my/ubuntu:v4
docker build # 使用Dockerfile创建镜像(推荐)

docker search # 从registry仓库搜索镜像
docker search php:5.6-fpm  #从Docker Hub查找镜像名php5.6-fpm
docker search -s 10 java   #从Docker Hub查找所有镜像名包含java,并且收藏数大于10的镜像

docker pull # 从仓库下载镜像到本地 
docker pull richarvey/nginx-php-fpm

下载镜像记录

root@bluedonchen-PowerEdge-T410:/home/bluedonchen# docker pull richarvey/nginx-php-fpm
Using default tag: latest
latest: Pulling from richarvey/nginx-php-fpm
911c6d0c7995: Pull complete 
2527cc05836d: Pull complete 
3299172a2d6d: Pull complete 
05782106624f: Pull complete 
3e3261543ec8: Pull complete 
ce1c845d4246: Pull complete 
e005e70f55dc: Pull complete 
84403a106e16: Pull complete 
e4fc13f7949f: Pull complete 
2a53e72ea7b9: Pull complete 
d791f6b71f27: Pull complete 
f6df331656e7: Pull complete 
5381ec390ca6: Pull complete 
2e9a52704f07: Pull complete 
7a8ef513204e: Pull complete 
df19144db16b: Pull complete 
b832cce98a16: Pull complete 
6370d6a48a11: Pull complete 
924e29dc442b: Pull complete 
2bc9f6bfc6a8: Pull complete 
72e2f93784df: Pull complete 
cb7fbeead5a1: Pull complete 
276d9744a2fb: Pull complete 
486d85bb5539: Pull complete 
4b2c3b875d6a: Pull complete 
347e2742b221: Pull complete 
90218f1356c9: Pull complete 
451db447c8a9: Pull complete 
27f73f3b662a: Pull complete 
8fa8d5b5be53: Pull complete 
Digest: sha256:5d8b5985af7e11ec08747f25dd8bf7c2f7f0b2c590740a005f326ff5f805c09d
Status: Downloaded newer image for richarvey/nginx-php-fpm:latest


docker info  #显示 Docker 系统信息,包括镜像和容器数。
docker version  #显示 Docker 版本信息。参数-f :指定返回值的模板文件。

运行镜像

docker run -t -i bitnami/redis /bin/bash
docker run -it --name bdredis bitnami/redis /bin/bash
#其中,-t 选项让Docker分配一个伪终端(pseudo-tty)并绑定到容器的标准输入上, -i 则让容器的标准输入保持打开。也可以合并起来写
# 不加-t -i的话,执行完就退出容器例如,下面的命令输出一个 “Hello World”,之后终止容器。
# 可以通过添加 -d 参数来实现。例如下面的命令会在后台运行容器。

docker attach 63e018246bb8
docker start 63e018246bb8
# 默认情况下,如果使用ctrl-d退出container,那么container也会stop,按ctrl-p ctrl-q可以退出到宿主机,而保持container仍然在运行.然后要进入再使用docker attach
#输入exit或ctrl+d

docker run --name some-redis -d redis
docker run -d --name redis-6379 -p 6379:6379 hakimdstx/nodes-redis:4.0.1
docker run -d --name chen-redis -p 6379:6379 redis

仓库地址

https://hub.docker.com/

镜像信息查看

root@bluedonchen-PowerEdge-T410:/home/bluedonchen# docker inspect lnp | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
root@bluedonchen-PowerEdge-T410:/home/bluedonchen# curl -I 172.17.0.2
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Aug 2018 06:49:21 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.2.8

相关文章

网友评论

      本文标题:docker的初使用

      本文链接:https://www.haomeiwen.com/subject/aeqavftx.html