What is the difference b/w “service docker start”

2019-04-13 12:50发布

I'm new to docker, and want to restart docker daemon. I want to add the OPTS to start docker like:

docker --registry-mirror=http://<my-docker-mirror-host> -d

I want to know what is they difference? Does they start the same thing?

By the way, I just use above command in my boot2docker, it did't work at all.

标签: docker
2条回答
Emotional °昔
2楼-- · 2019-04-13 13:18

if you use service docker start then it will start docker as service with docker's upstart configuration file, e.g. /etc/default/docker for ubuntu and /etc/sysconfig/docker for centos.

if you use docker -d it will run docker in daemon mode.

if you want define your own registry-mirror for docker, you can do this:

ubuntu

$ echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://<my-docker-mirror-host>\"" | sudo tee -a /etc/default/docker
$ sudo service docker restart

centos

sudo sed -i 's|other_args=|other_args=--registry-mirror=http://<my-docker-mirror-host> |g' /etc/sysconfig/docker
sudo sed -i "s|OPTIONS='|OPTIONS='--registry-mirror=http://<my-docker-mirror-host> |g" /etc/sysconfig/docker
sudo service docker restart

mac

boot2docker up
boot2docker ssh "echo $'EXTRA_ARGS=\"--registry-mirror=http://<my-docker-mirror-host>\"' | sudo tee -a /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart”

then your docker service with run with your own registry mirror.

查看更多
小情绪 Triste *
3楼-- · 2019-04-13 13:38

To answer your questions (which are valid for debian/ubuntu, I don't have tinylinux handy to test which is used by boot2docker):

  • service docker start will run a startup script in /etc/init.d/docker
  • docker -d is the manual version of the previous script, useful when you want to run docker in debug mode. I suspect the example you gave will not do the same thing, because there are more options specified in the service script.
  • if you want to add more docker command options, edit the /etc/default/docker file

Update after OP's comments:

To add your new switch, you need to specifically edit the variable (which maybe exported) DOCKER_OPTS and add your option to the end of the existing options.

My /etc/default/docker options are:

export DOCKER_OPTS="--tlsverify --tlscacert=/etc/docker/ca.pem 
--tlskey=/etc/docker/server-key.pem --tlscert=/etc/docker/server.pem --label=provider=XXXX 
--host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2376" 

To add the registry-mirror I would edit the DOCKER_OPTS to look like this

export DOCKER_OPTS="--tlsverify --tlscacert=/etc/docker/ca.pem 
--tlskey=/etc/docker/server-key.pem --tlscert=/etc/docker/server.pem --label=provider=XXXX 
--host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2376 
--registry- mirror=192.168.59.103:5555"
查看更多
登录 后发表回答