以前的笔记 整理下
开启

[root@wecash /]# service docker restart
Redirecting to /bin/systemctl restart  docker.service
[root@wecash /]# 
[root@wecash /]# 
[root@wecash /]# docker version
Client:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      1398f24/1.12.6
 Built:           Fri May 26 17:28:18 2017
 OS/Arch:         linux/amd64

Server:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      1398f24/1.12.6
 Built:           Fri May 26 17:28:18 2017
 OS/Arch:         l


 关闭


 [root@wecash /]# service docker stop
Redirecting to /bin/systemctl stop  docker.service
[root@wecash /]# docker version
Client:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      1398f24/1.12.6
 Built:           Fri May 26 17:28:18 2017
 OS/Arch:         linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
[root@wecash /]# 

搜索可用镜像

[root@wecash /]# service docker restart
Redirecting to /bin/systemctl restart  docker.service
[root@wecash /]# docker search redis
INDEX       NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/redis                     Redis is an open source key-value store th...   3794      [OK]       
docker.io   docker.io/bitnami/redis             Bitnami Redis Docker Image                      49                   [OK]
docker.io   docker.io/torusware/speedus-redis   Always updated official Redis docker image...   32                   [OK]
docker.io   docker.io/webhippie/redis           Docker images for redis                         7                    [OK]
docker.io   docker.io/anapsix/redis             11MB Redis server image over AlpineLinux        6                    [OK]
docker.io   docker.io/clue/redis-benchmark      A minimal docker image to ease running the...   3                    [OK]
docker.io   docker.io/williamyeh/redis          Redis image for Docker                          3                    [OK]
docker.io   docker.io/abzcoding/tomcat-redis    a tomcat container with redis as session m...   2                    [OK]
docker.io   docker.io/centos/redis              Redis built for CentOS                          2                    [OK]
docker.io   docker.io/unblibraries/redis        Leverages phusion/baseimage to deploy a ba...   2                    [OK]
docker.io   docker.io/frodenas/redis            A Docker Image for Redis                        1                    [OK]
docker.io   docker.io/greytip/redis             redis 3.0.3                                     1                    [OK]
docker.io   docker.io/miko2u/redis              Redis                                           1                    [OK]
docker.io   docker.io/xataz/redis               Light redis image                               1                    [OK]
docker.io   docker.io/appelgriebsch/redis       Configurable redis container based on Alpi...   0                    [OK]
docker.io   docker.io/cloudposse/redis          Standalone redis service                        0                    [OK]
docker.io   docker.io/continuouspipe/redis      Redis                                           0                    [OK]
docker.io   docker.io/drupaldocker/redis        Redis for Drupal                                0                    [OK]
docker.io   docker.io/khipu/redis               customized redis                                0                    [OK]
docker.io   docker.io/maestrano/redis           Redis is an open source key-value store th...   0                    [OK]
docker.io   docker.io/maxird/redis              Redis                                           0                    [OK]
docker.io   docker.io/nanobox/redis             Redis service for nanobox.io                    0                    [OK]
docker.io   docker.io/trelllis/redis            Redis Primary                                   0                    [OK]
docker.io   docker.io/watsco/redis              Watsco redis base                               0                    [OK]
docker.io   docker.io/yfix/redis                Yfix docker redis                               0                    [OK]

下载镜像

[root@wecash /]# docker pull docker.io/redis
Using default tag: latest
Trying to pull repository docker.io/library/redis ... 
latest: Pulling from docker.io/library/redis
10a267c67f42: Pull complete 
5b690bc4eaa6: Pull complete 
4cdd94354d2a: Pull complete 
71c1f30d820f: Pull complete 
c54584150374: Pull complete 
d1f9221193a6: Pull complete 
d45bc46b48e4: Pull complete 
Digest: sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf
[root@wecash /]# 

查看已有镜像

[root@wecash wecash]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     latest              a858478874d1        12 days ago         183.7 MB
[root@wecash wecash]# 


删除镜像:

docker rmi image-id
删除所有镜像
docker rmi ${docker images -q}



docker 容器的命令

运行镜像

docker run --name containerp-name -d image-name

--name 为容器取得名称
-d 标识detached 意味着执行完这句命令后控制台将不会呗阻碍,可继续输入命令操作;最后的image-name 是要使用哪个镜像来运行容器。

demo:

[root@wecash wecash]# docker run --name test-redis -d redis
836678bc8688fa78d51a4a94353ef2732d02dfa20c6ef6615de688f1b22c0984
[root@wecash wecash]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
836678bc8688        redis               "docker-entrypoint.sh"   27 seconds ago      Up 25 seconds       6379/tcp            test-redis
[root@wecash wecash]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES
836678bc8688        redis               "docker-entrypoint.sh"   About a minute ago   Up About a minute   6379/tcp            test-redis
[root@wecash wecash]# 

在外部访问docker的6379端口的时候不能让外部链接成功

在本机和本机的局域网是不能访问的,所以我们需要将dockers的端口映射倒当前主机的端口上

![image](http://note.youdao.com/favicon.ico)

[root@wecash wecash]# docker stop test-redis
test-redis
[root@wecash wecash]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@wecash wecash]# 

这么启动的方式才能让外部客户端访问倒redis
有个端口映射的过程。
[root@wecash wecash]# docker run -d -p 6379:6379 --name port-redis redis
b76fd516f4ecf9361c9a2f0deb596a1f6d650a2ce2dbce702cef0cd5e0826465
[root@wecash wecash]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b76fd516f4ec        redis               "docker-entrypoint.sh"   5 seconds ago       Up 3 seconds        0.0.0.0:6379->6379/tcp   port-redis
[root@wecash wecash]# 


查看防火墙状态

[root@wecash wecash]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2017-05-31 18:09:07 CST; 1h 0min ago
     Docs: man:firewalld(1)
 Main PID: 639 (firewalld)
   Memory: 0B
   CGroup: /system.slice/firewalld.service
           └─639 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C PREROUTING -m addrtype --dst-type LOCAL -j DOCKER' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C OUTPUT -m addrtype --dst-type LOCAL -j DOCKER ! --dst 127.0.0.0/8' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -i docker0 -j RETURN' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 -o docker0 -j ACCEPT' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 ! -o docker0 -j ACCEPT' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT' failed:
531 18:47:28 wecash firewalld[639]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -j DOCKER' failed:
[root@wecash wecash]# 

查看启动的镜像的日志


port-redis 是一个 --name 启动的镜像名称


[root@wecash wecash]# docker logs port-redis
1:C 31 May 11:25:11.902 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
1:M 31 May 11:25:11.907 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 31 May 11:25:11.907 # Server started, Redis version 3.2.9
1:M 31 May 11:25:11.907 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 31 May 11:25:11.908 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 31 May 11:25:11.908 * The server is now ready to accept connections on port 6379
1:signal-handler (1496230174) Received SIGTERM scheduling shutdown...
1:M 31 May 11:29:34.369 # User requested shutdown...
1:M 31 May 11:29:34.369 * Saving the final RDB snapshot before exiting.
1:M 31 May 11:29:34.374 * DB saved on disk
1:M 31 May 11:29:34.374 # Redis is now ready to exit, bye bye...
[root@wecash wecash]# 
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐