docker设置并运行部分命令及原文

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.

时间: 2024-08-01 19:49:37

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

在docker中用Tomcat运行web项目

本文旨在用最通俗的语言讲述最枯燥的基本知识 上一篇文章<为什么要用docker>已经讲述了什么是docker以及我们要用docker的原因,并且讲解了如何安装docker.这时候很多读者磨拳擦脚跃跃欲试但却发现安装好docker之后就无从下手了,那么,接下来,小编会从以下方面讲述docker的一些基础知识,当然,理论都是生硬的,所以小编选取了javaweb项目中最常用的一个软件--tomcat的安装和使用来引导学习一些docker相关的知识,借此让读者能够从实战的角度去理解docker为什么会

[docker] 02 CentOS安装docker(包含失败),安装命令简介,以及docker核心概念

主要内容: 一.安装docker(包含卸载重新安装) 二.配置docker服务 三.安装命令简介 四.docker核心概念 一.安装docker 1.1. 通过uname -r查看系统版本,为什么要查看系统版本呢?因为docker对CentOS有以下要求: a. CentOS 7及以后的版本 b. 64位操作系统 c. 内核版本至少3.10 1.2. 支持devicemapper存储类型 sudo yum update sudo yum install -y device-mapper-pers

docker Dockerfile里使用的命令说明

一,dockerfile格式 注释# 指令 参数 指令不区分大小写,但是推荐全部大写指令. 指令从上到下顺序被执行 第一个指令必须是[FROM],指示出要使用的基础镜像. 执行docker file时,如果使用到了别的配置文件,这些配置文件不能放到[执行docker file目录]的父目录,但可以放到子目录. 在执行docker file目录下,可以放一个隐藏文件(.dockerignore),里面存放的是build时不需要的文件.可以使用通配符去指定.比如,某个子目录里10个文件,build时

Docker 搭建 Tomcat 运行环境

使用 Docker 搭建 Tomcat 运行环境 1. Docker与虚拟机的区别 2 搭建过程 2.1 准备宿主系统 准备一个 CentOS 7操作系统,具体要求如下: · 必须是 64 位操作系统 · 建议内核在 3.8 以上 查看 CentOS 7系统内核: [[email protected] ~]# uname  -r 3.10.0-327.el7.x86_64 2.2 安装Docker [[email protected] ~]# yum  -y   install   docker

理解ASP.NET 5运行时命令:DNVM, DNX, 和DNU

ASP.NET 5 引入了一个新型的运行时,让我们可以现场交付模式组合式构建应用程序,而不依赖于宿主机上的.NET框架.这种新模式为我们提供了命令行工具(DNVM.DNX.DNU)用于管理我们的.net 版本,依赖的库和运行环境,我们可以不需要Visual Studio,只需要一个文本编辑器和命令行就可以开发一个应用程序. 了解.NET 版本管理器 (DNVM) 之间 ,.NET 执行环境 (DNX) 和.NET 开发实用程序 (DNU) 之间的关系是开发 ASP.NET 5的根本.在这篇文章我

Docker源码分析之——Docker Client的启动与命令执行

在上文Docker源码分析之--Docker Daemon的启动 中,介绍了Docker Daemon进程的启动.Docker Daemon可以认为是一个Docker作为Server的运行载体,而真正发送关于docker container操作的请求的载体,在于Docker Client.本文从Docker源码的角度,分析Docker Client启动与执行请求的过程. Docker Client启动的流程与Docker Daemon启动的过程相仿.首先执行reexec.Init():随后解析f

Docker学习总结之Run命令介绍

在使用Docker时,执行最多的命令某过于run了.这个命令可以说是所有docker操作的入口.在Docker官方Reference中单独列出了一个章节来介绍Run的各种参数使用,也足以看出Docker run的重要性.有感于此,我感觉有必要好好学习一下Run命令,因此特意看了一下Run命令介绍,结合日常中的使用心得,分享一下.以下文档大部分翻译于Docker 官方Reference,肯定会存在不少错误之处,希望能抛砖引玉,大家共同讨论. Docker在执行时会将相关进程封装到相互隔离的容器(c

使用 MaxCompute(原ODPS) java sdk 运行安全相关命令

转自zhenhong 使用 MaxCompute console 的同学,可能都使用过 odps 安全相关的命令.官方文档上有详细的 odps 安全指南,并给出了安全相关命令列表. 简而言之,权限管理.项目空间安全配置以及用户及授权管理都属于 odps 安全命令相关的范畴. 再直白一点,以下列关键字开头的命令,都是 odps 安全相关操作命令: GRANT/REVOKE ... SHOW GRANTS/ACL/PACKAGE/LABEL/ROLE/PRINCIPALS SHOW PRIV/PRI

使用 Docker 搭建 Tomcat 运行环境

转自: http://m.oschina.net/blog/616526, 版权归原作者所有. 1 Docker与虚拟机     2 搭建过程 2.1 准备宿主系统 准备一个 CentOS 7操作系统,具体要求如下: 必须是 64 位操作系统 建议内核在 3.8 以上 通过以下命令查看您的 CentOS 内核: # uname -r 2.2 安装Docker # yum install docker 可使用以下命令,查看 Docker 是否安装成功: # docker version 若输出了