docker设置并运行部分命令及原文
2015-07-07 14:18
876 查看
1.设置开机启动
If you want Docker to start at boot, you should also:
2. 启动,停止,重启
$ sudo systemctl start docker $ sudo systemctl stop docker $ sudo systemctl restart docker
3.开启本地和远程
修改/etc/sysconfig/docker文件,替换
-H fd://为
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
$ ps aux | grep docker | grep -v grep
In a production environment, system administrators typically configure the
Some of the daemon’s options are:
Here is a an example of running the
These options :
Enable
Set
Listen for connections on
The command line reference has the complete list of daemon flags with explanations.
After successfully installing Docker for Ubuntu, you can check the running status using Upstart in this way:
To configure Docker options:
Log into your host as a user with
If you don’t have one, create the
Open the file with your favorite editor.
Add a
These options :
Enable
Set
Listen for connections on
The command line reference has the complete list of daemon flags with explanations.
Save and close the file.
Restart the
Verify that the
After successfully installing Docker for CentOS/Red Hat Enterprise Linux/Fedora, you can check the running status in this way:
If you want Docker to start at boot, you should also:
By default, systemd services are located either in
To configure Docker options:
Log into your host as a user with
If you don’t have one, create the
Open the file with your favorite editor.
Add a
These options :
Enable
Set
Listen for connections on
The command line reference has the complete list of daemon flags with explanations.
Save and close the file.
Restart the
Verify that the
Note: Using and configuring journal is an advanced topic and is beyond the scope of this article.
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
dockerdaemon is running as specified with the
pscommand.
$ ps aux | grep docker | grep -v grep
Configuring and running Docker on various distributions
After successfully installing Docker, thedockerdaemon 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
SysVinit,
Upstart, or
systemdto manage the
dockerdaemon’s start and stop.
Running the docker daemon directly
Thedockerdaemon can be run directly using the
-doption. 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 thedockerdaemon directly by running
docker -dinstead of using a process manager, you can append the configuration options to the
dockerrun command directly. Just like the
-doption, other options can be passed to the
dockerdaemon 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. |
dockerdaemon 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
tlsto true with the server certificate and key specified using
--tlscertand
--tlskeyrespectively
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 of14.04, Ubuntu uses Upstart as a process manager. By default, Upstart jobs are located in
/etc/initand the
dockerUpstart 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 thedockerdaemon using
$ sudo start docker $ sudo stop docker $ sudo restart docker
Configuring Docker
You configure thedockerdaemon in the
/etc/default/dockerfile on your system. You do this by specifying values in a
DOCKER_OPTSvariable.
To configure Docker options:
Log into your host as a user with
sudoor
rootprivileges.
If you don’t have one, create the
/etc/default/dockerfile on your host. Depending on how you installed Docker, you may already have this file.
Open the file with your favorite editor.
$ sudo vi /etc/default/docker
Add a
DOCKER_OPTSvariable with the following options. These options are appended to the
dockerdaemon’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
tlsto true with the server certificate and key specified using
--tlscertand
--tlskeyrespectively
Listen for connections on
tcp://192.168.59.3:2376
The command line reference has the complete list of daemon flags with explanations.
Save and close the file.
Restart the
dockerdaemon.
$ sudo restart docker
Verify that the
dockerdaemon is running as specified with the
pscommand.
$ ps aux | grep docker | grep -v grep
Logs
By default logs for Upstart jobs are located in/var/log/upstartand the logs for
dockerdaemon 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 of7.x, CentOS and RHEL use
systemdas the process manager. As of
21, Fedora uses
systemdas 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 thedockerdaemon 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 thedockerdaemon in the
/etc/sysconfig/dockerfile 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
OPTIONSand 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
dockerdaemon.
By default, systemd services are located either in
/etc/systemd/service,
/lib/systemd/systemor
/usr/lib/systemd/system. The
docker.servicefile can be found in either of these three directories depending on your host.
To configure Docker options:
Log into your host as a user with
sudoor
rootprivileges.
If you don’t have one, create the
/etc/sysconfig/dockerfile on your host. Depending on how you installed Docker, you may already have this file.
Open the file with your favorite editor.
$ sudo vi /etc/sysconfig/docker
Add a
OPTIONSvariable with the following options. These options are appended to the command that starts the
dockerdaemon.
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
tlsto true with the server certificate and key specified using
--tlscertand
--tlskeyrespectively
Listen for connections on
tcp://192.168.59.3:2376
The command line reference has the complete list of daemon flags with explanations.
Save and close the file.
Restart the
dockerdaemon.
$ sudo service docker restart
Verify that the
dockerdaemon is running as specified with the
pscommand.
$ ps aux | grep docker | grep -v grep
Logs
systemd has its own logging system called the journal. The logs for thedockerdaemon 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.
相关文章推荐
- CentOS7中Docker文件挂载,容器中没有执行权限
- Docker 快速入门使用
- Docker为容器分配指定物理网段的静态IP
- 使用Docker部署Gitlab
- docker学习笔记
- 学习 Docker - 入门
- Ubuntu 12.04 LTS安装Docker
- 使用Docker、CoreOS、Mesos部署可扩展的Web应用
- ubuntu15.04中的docker...2
- Docker build报错FATA[0000]
- 利用Docker建立服务器和docker容器的监视系统
- Docker 开发实践
- 初始docker(三)
- Docker学习笔记 — Swarm搭建Docker集群
- jenkins script call docker
- ubuntu15.04中的docker...1
- CentOS7安装Docker,运行Nginx镜像、Centos镜像
- docker安装升级linux内核(2.6.32->3.10.81),安装成功!
- Centos 7安装Docker
- Docker在github上的站点