1.设置开机启动

If you want Docker to start at boot, you should also:

$ sudo systemctl enable docker

2. 启动,停止,重启

$ sudo systemctl start docker

$ sudo systemctl stop docker

$ sudo systemctl restart docker

3.开启本地和远程

修改/etc/sysconfig/docker文件,替换

-H fd://为

-H unix:///var/run/docker.sock -H 0.0.0.0:2376

4.boot2docker启动参数

/usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// -H tcp://0.0.0.0:2376 --tlsverify --tlscacert=/var/lib/boot2docker/tls/ca.pem --tlscert=/var/lib/

5. 确认docker启动

Verify that the docker daemon is running as specified with the ps command.

$ ps aux | grep docker | grep -v grep

Configuring and running Docker on various distributions

After successfully installing Docker, the docker daemon runs with its default configuration.

In a production environment, system administrators typically configure the dockerdaemon to start and stop according to an organization’s requirements. In most cases, the system administrator configures a process manager such as SysVinitUpstart, or systemd to manage the docker daemon’s start and stop.

Running the docker daemon directly

The docker daemon can be run directly using the -d option. By default it listens on the Unix socket unix:///var/run/docker.sock

$ docker -d

INFO[0000] +job init_networkdriver()
INFO[0000] +job serveapi(unix:///var/run/docker.sock)
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
...
...

Configuring the docker daemon directly

If you’re running the docker daemon directly by running docker -d instead of using a process manager, you can append the configuration options to the dockerrun command directly. Just like the -d option, other options can be passed to the docker daemon to configure it.

Some of the daemon’s options are:

Flag Description
-D--debug=false Enable or disable debug mode. By default, this is false.
-H,--host=[] Daemon socket(s) to connect to.
--tls=false Enable or disable TLS. By default, this is false.

Here is a an example of running the docker daemon with configuration options:

$ docker -d -D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376

These options :

  • Enable -D (debug) mode
  • Set tls to true with the server certificate and key specified using --tlscert and --tlskey respectively
  • Listen for connections on tcp://192.168.59.3:2376

The command line reference has the complete list of daemon flags with explanations.

Ubuntu

As of 14.04, Ubuntu uses Upstart as a process manager. By default, Upstart jobs are located in  /etc/init and the docker Upstart job can be found at /etc/init/docker.conf.

After successfully installing Docker for Ubuntu, you can check the running status using Upstart in this way:

$ sudo status docker

docker start/running, process 989

Running Docker

You can start/stop/restart the docker daemon using

$ sudo start docker

$ sudo stop docker

$ sudo restart docker

Configuring Docker

You configure the docker daemon in the /etc/default/docker file on your system. You do this by specifying values in a DOCKER_OPTS variable.

To configure Docker options:

  1. Log into your host as a user with sudo or root privileges.

  2. If you don’t have one, create the /etc/default/docker file on your host. Depending on how you installed Docker, you may already have this file.

  3. Open the file with your favorite editor.

    $ sudo vi /etc/default/docker
  4. Add a DOCKER_OPTS variable with the following options. These options are appended to the docker daemon’s run command.

    DOCKER_OPTS="-D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376"

These options :

  • Enable -D (debug) mode
  • Set tls to true with the server certificate and key specified using --tlscert and --tlskey respectively
  • Listen for connections on tcp://192.168.59.3:2376

The command line reference has the complete list of daemon flags with explanations.

  1. Save and close the file.

  2. Restart the docker daemon.

    $ sudo restart docker
  3. Verify that the docker daemon is running as specified with the ps command.

    $ ps aux | grep docker | grep -v grep

Logs

By default logs for Upstart jobs are located in /var/log/upstart and the logs for docker daemon can be located at /var/log/upstart/docker.log

$ tail -f /var/log/upstart/docker.log
INFO[0000] Loading containers: done.
INFO[0000] docker daemon: 1.6.0 4749651; execdriver: native-0.2; graphdriver: aufs
INFO[0000] +job acceptconnections()
INFO[0000] -job acceptconnections() = OK (0)
INFO[0000] Daemon has completed initialization

CentOS / Red Hat Enterprise Linux / Fedora

As of 7.x, CentOS and RHEL use systemd as the process manager. As of 21, Fedora uses systemd as its process manager.

After successfully installing Docker for CentOS/Red Hat Enterprise Linux/Fedora, you can check the running status in this way:

$ sudo systemctl status docker

Running Docker

You can start/stop/restart the docker daemon using

$ sudo systemctl start docker

$ sudo systemctl stop docker

$ sudo systemctl restart docker

If you want Docker to start at boot, you should also:

$ sudo systemctl enable docker

Configuring Docker

You configure the docker daemon in the /etc/sysconfig/docker file on your host. You do this by specifying values in a variable. For CentOS 7.x and RHEL 7.x, the name of the variable is OPTIONS and for CentOS 6.x and RHEL 6.x, the name of the variable is other_args. For this section, we will use CentOS 7.x as an example to configure the docker daemon.

By default, systemd services are located either in /etc/systemd/service/lib/systemd/system or /usr/lib/systemd/system. The docker.service file can be found in either of these three directories depending on your host.

To configure Docker options:

  1. Log into your host as a user with sudo or root privileges.

  2. If you don’t have one, create the /etc/sysconfig/docker file on your host. Depending on how you installed Docker, you may already have this file.

  3. Open the file with your favorite editor.

    $ sudo vi /etc/sysconfig/docker
  4. Add a OPTIONS variable with the following options. These options are appended to the command that starts the docker daemon.

    OPTIONS="-D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376"

These options :

  • Enable -D (debug) mode
  • Set tls to true with the server certificate and key specified using --tlscert and --tlskey respectively
  • Listen for connections on tcp://192.168.59.3:2376

The command line reference has the complete list of daemon flags with explanations.

  1. Save and close the file.

  2. Restart the docker daemon.

    $ sudo service docker restart
  3. Verify that the docker daemon is running as specified with the ps command.

    $ ps aux | grep docker | grep -v grep

Logs

systemd has its own logging system called the journal. The logs for the dockerdaemon can be viewed using journalctl -u docker

$ sudo journalctl -u docker
May 06 00:22:05 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
May 06 00:22:05 localhost.localdomain docker[2495]: time="2015-05-06T00:22:05Z" level="info" msg="+job serveapi(unix:///var/run/docker.sock)"
May 06 00:22:05 localhost.localdomain docker[2495]: time="2015-05-06T00:22:05Z" level="info" msg="Listening for HTTP on unix (/var/run/docker.sock)"
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job init_networkdriver()"
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job init_networkdriver() = OK (0)"
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: start."
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="Loading containers: done."
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="docker daemon: 1.5.0-dev fc0329b/1.5.0; execdriver: native-0.2; graphdriver: devicemapper"
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="+job acceptconnections()"
May 06 00:22:06 localhost.localdomain docker[2495]: time="2015-05-06T00:22:06Z" level="info" msg="-job acceptconnections() = OK (0)"

Note: Using and configuring journal is an advanced topic and is beyond the scope of this article.

docker设置并运行部分命令及原文的更多相关文章

  1. Docker容器管理——运行容器命令

    1.容器的生命周期(***重要,需要理解) 容器启动后,执行的第一条命令的PID为1     ========================>>>>>>>& ...

  2. Docker Swarm 日常运维命令笔记

    之前介绍了Docker管理工具-Swarm部署记录,这里简单总结下Docker Swarm的日常维护命令,以作为平时运维笔记. Swarm作为一个管理Docker集群的工具,首先需要将其部署起来,可以 ...

  3. 在eclipse中运行maven命令没有反应,console也不打印信息

    eclipse的maven项目中,在run as  执行maven命令的时候发现毫无反应,console也不打印信息,原因是因为没有传参数,解决办法如下:①打开eclipse的window菜单: ②接 ...

  4. docker rmi 导致后面的命令不执行问题 Dockerfile设置时区问题

    docker rmi 导致后面的命令不执行问题 把ca=`docker rmi sendemail-service` echo $ca改成docker rmi sendemail-service -f ...

  5. Docker学习总结之Run命令介绍

    Docker学习总结之Run命令介绍 本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 在使用Docker时,执行最多的命令某 ...

  6. 在 Docker 容器中运行应用程序

    案例说明 运行 3 个容器,实现对网站的监控. 三个容器的说明: 容器 web: 创建自 nginx 映像,使用 80 端口,运行于后台,实现 web 服务. 容器 mailer: 该容器中运行一个 ...

  7. Docker安装+HelloWorld+运行Tomcat

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 上一篇已经讲解了为什么需要Docker?,相信大家已 ...

  8. 使用MaxCompute Java SDK运行安全相关命令

    使用MaxCompute Console的同学,可能都使用过MaxCompute安全相关的命令.官方文档上有详细的MaxCompute安全指南,并给出了安全相关语句汇总.   简而言之,权限管理.列级 ...

  9. Docker 共有 13 个管理命令和 41 个通用命令,以下是常用 Docker 命令列表

    开发人员一直在努力提高 Docker 的使用率和性能,命令也在不停变化.Docker 命令经常被弃用,或被替换为更新且更有效的命令,本文总结了近年来资深专家最常用的命令列表并给出部分使用方法. 目前, ...

随机推荐

  1. Python学习笔记 for windows 三

    多重继承 继承是面向对象编程的一个重要的方式,因为通过继承,子类就可以扩展父类的功能. 哺乳类:能跑的哺乳类,能飞的哺乳类: 鸟类:能跑的鸟类,能飞的鸟类. class Animal(object): ...

  2. golang: 常用数据类型底层结构分析

    虽然golang是用C实现的,并且被称为下一代的C语言,但是golang跟C的差别还是很大的.它定义了一套很丰富的数据类型及数据结构,这些类型和结构或者是直接映射为C的数据类型,或者是用C struc ...

  3. Quartz2D 编程指南(四)位图与图像遮罩、CoreGraphics 绘制 Layer

    概览 图形上下文 路径 颜色与颜色空间 变换 图案 阴影 渐变 透明层 Quartz 2D 中的数据管理 位图与图像遮罩 CoreGraphics 绘制 Layer 位图与图像遮罩 简介 位图与图像遮 ...

  4. 制作自己的嵌入式Linux电脑_转

    制作自己的嵌入式Linux电脑 http://os.51cto.com/art/201409/450334.htm 原文链接:http://blog.jobbole.com/75414/ 包含器件选择 ...

  5. Python之路----------time模块

    时间模块是常用的模块 一.time模块 import time print(time.clock())#返回处理器时间,3.3开始已经屏蔽. print(time.altzone)#返回与UTC时间差 ...

  6. 设计模式学习笔记c++版——单例模式

    特别注意单例模式c++实现在main.cpp中引用的时候要去申明下: Singleton * Singleton::m_Instance = NULL; //定义性声明 不然会报错:无法解析的外部符号 ...

  7. 快速查找和你聊天人的IP和具体的物理所在地址

    附言 : 对于中秋佳节没有回家也没有外出的我,亦然选择闭关.本来是打算把这个公众号作为测试号的.但是发现这个号已经有注册有一年多了,怪可惜的!所以就用来发些教程图文,供给大家共同学习,也对自己进行不定 ...

  8. svg学习(九)path

    <path> 标签用来定义路径. 下面的命令可用于路径数据: M = moveto L = lineto H = horizontal lineto V = vertical lineto ...

  9. 一个关于Random算法的问题

    指定范围数字,生成随机序列,数字不连续:例如:范围[1-5]  输入 1 3 5 2 4 下面分享两种算法: 算法1:RmNum<RmNext 下面这种算法计算是无压力的 /// <sum ...

  10. GetKeyboardType获取键盘类型(通过键盘可初步判断用户使用的是台式电脑还是笔记本电脑)

    函数功能:该函数获取系统当前键盘的信息. int WINAPI GetKeyboardType( __in int nTypeFlag ); 参数说明:nTypeFlag:指定要获取的键盘信息的类型, ...